Global Constants - Script Access

Is it possible to define global constants and access them from within a Groovy script?

So far I’ve tried this with no success:

def globalservice = GLOBALS.getRsServiceProvider(GlobalConstantsService.class);

String globalc = globalservice.getConstantFor("constant name");

Is this possible?

Hi Tom,

your code is almost correct: Instead of getRsServiceProvider() use getRsService():

import net.datenwerke.rs.globalconstants.service.globalconstants.GlobalConstantsService
def globalservice = GLOBALS.getRsService(GlobalConstantsService.class);

String globalc = globalservice.getConstantFor("RS_DOKU_LOGO");

The ServiceProvider creates a wrapper object that needs an additional get()

import net.datenwerke.rs.globalconstants.service.globalconstants.GlobalConstantsService
def globalservice = GLOBALS.getRsServiceProvider(GlobalConstantsService.class);

String globalc = globalservice.get().getConstantFor("RS_DOKU_LOGO");

This is useful for example when you want to define a callback that gets created before the respective service is available.

Cheers,
Thorsten