Access Service Parameters of Another Groovy Service

   Journey Manager (JM) The transaction engine for the platform.  |    Form Builder Platform Developer  |  All versions This feature is related to all versions.

The requirement was for a 'Form Prefill' service to be able to access the service parameters configured within an existing 'Delivery Process' service. The use case being that there was some common configuration between the services and that they wished to maintain these settings in a single location. As it turns out this functionality is built into the Manager's Java libraries and it was fairly straight forward to implement the solution. Start by adding the following imports to the top of your Groovy script:

import com.avoka.fc.core.service.IServiceDefinitionAware
        
import com.avoka.fc.core.service.ServiceLocator
        
import com.avoka.fc.core.entity.ServiceDefinition

Then, use the 'ServiceLocator' class to find the service with the parameters you want to access and retrieve its service definition:

IServiceDefinitionAware tmService = ServiceLocator.getServiceForName("The Existing Service's Name")
        
ServiceDefinition serviceDefinition = tmService.getServiceDefinition()

Finally, get the service parameter you're looking for and where necessary access the value it contains:

def param = serviceDefinition.getServiceParameter("The Parameter's Name");
        
def paramValue = param.getValue();

Next, learn how to view Transact functions.