You are not logged in.
I understand how to define global constants in ReportServer and that they can be used in reports such as Dynamic Lists, BIRT, Jasper, etc.
However, I've not found a way to use them in Groovy scripts. Could anyone share how this could be achieved? Thank you!
Reference: https://reportserver.net/en/guides/admi … Constants/
Offline
Hi Johann,
you can use services for this. Here are the relevant documents:
The javadocs can be found here: https://reportserver.net/api/current/javadoc/index.html
List of entities: https://reportserver.net/api/current/entities.html
List of hooks: https://reportserver.net/api/current/hooks.html
List of services: https://reportserver.net/api/current/services.html
So in your case, you can see in the services list: GlobalConstantsService
which has getConstantFor(java.lang.String name) for reading the value of a given global constant.
For using the service, you can just type:
def globalConstantsService = GLOBALS.getInstance(GlobalConstantsService)
Regards,
Eduardo
Offline
Got it, thanks so much Eduardo!
On a similar note, how about if we were to import groovy methods (from other files) instead of importing constants? Would using GLOBALS still be the right solution?
Offline
I have found a solution for importing methods, which I came across while trying out the demo. Essentially, we can create a Groovy helper file containing the relevant methods and execute it in the Groovy script using:
GLOBALS.exec(‘path/to/lib.groovy’)
Offline
Hi Johann,
thanks for letting us know about your solution.
Regards,
Eduardo
Offline