#1 2015-08-09 21:08:20

tomharney
Member
Registered: 2014-03-11

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?

Offline

#2 2015-08-09 21:42:10

Thorsten J. Krause
datenwerke
Registered: 2012-02-15
Website

Re: Global Constants - Script Access

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

Offline

Board footer

Powered by FluxBB