#1 2022-06-01 04:06:39

Johann
Member
Registered: 2022-05-30

How to access ReportServer global constants from Groovy script

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

#2 2022-06-01 09:20:50

eduardo
Administrator
Registered: 2016-11-01
Website

Re: How to access ReportServer global constants from Groovy script

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

#3 2022-06-01 10:32:40

Johann
Member
Registered: 2022-05-30

Re: How to access ReportServer global constants from Groovy script

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

#4 2022-06-07 09:06:35

Johann
Member
Registered: 2022-05-30

Re: How to access ReportServer global constants from Groovy script

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

#5 2022-06-07 09:10:53

eduardo
Administrator
Registered: 2016-11-01
Website

Re: How to access ReportServer global constants from Groovy script

Hi Johann,

thanks for letting us know about your solution.

Regards,
Eduardo

Offline

Board footer

Powered by FluxBB