It is possibile to execute the operation chain contained in an Operation Module from a Script Unit. Suppose to have an Operation Module like the image on the right. If we want to execute the Operation Module in a Script Unit, we must first instatiate an RTXOperationUnitService, which is the service that describes the behaviour of a generic Operation Unit. After that, we have to retrieve the ids of the input parameters of the Operation Module in order to provide actual values to them. The OperationModuleService provides methods that allows you to retrieve the ids of the parameters basing on their names. In order to correctly execute the Operation Module, we have to instatiate two different HashMap Objects: the first one will contain the Local Context and the second one will contain the Session Context.
Here is an example of a Script Unit, like this one in the example below, which invoke the operation unit service of the Operation Module in the first model example.
#input String code, String name, Double price
import java.util.HashMap;
import java.util.Map;
import com.webratio.rtx.RTXOperationUnitService;
import com.webratio.rtx.core.OperationModuleService;
//Instantiate the operation unit service using the id of the operation module (i.e. "opmXXX")
RTXOperationUnitService opmService = ( RTXOperationUnitService ) rtx.getService("opm3");
//Instatiate the localContext Map
Map localContext = new HashMap();
//Instatiate the sessionContext Map
Map sessionContext = new HashMap();
//Retrieve the input collector parameter ids using their names
String codeInput = ((OperationModuleService)opmService).getInputParameterIdByName("codeParam");
String nameInput = ((OperationModuleService)opmService).getInputParameterIdByName("nameParam");
String priceInput = ((OperationModuleService)opmService).getInputParameterIdByName("priceParam");
//Put the value of the parameter in the localContext map
localContext.put(codeInput, code);
localContext.put(nameInput, name);
localContext.put(priceInput, price);
opmService.execute(localContext, sessionContext);
When the execute method has been executed, the Operation Module service ends and the Script Unit continues its classic execution.