Tips & Tricks - Groovy conditions in a process
In the "Processes" module, conditions can be controlled using Groovy, thereby making it possible to react to request values, among other things. In the example application, which you can download here as of Intrexx version 12.0.0 and import as usual with the process that is also included, a release is to be triggered by clicking on a button and the data record is to be saved. Another button, the "Cancel release" button, removes the release and saves the record as well.
The included process is disabled during import. To test the example application, activate the process after the import is finished.
In the example application, the "Release" button is configured with the "Save" action and the "rq_action" parameter. "rq_action" is given the static value "release".
The "Unrelease" button is also configured with the "Save" action and the "rq_action" parameter. rq_action is given the static value "notReleased" here.
In the process, the data group event handler responds to the addition or modification of the record.
The Groovy script entered in the properties dialog of the Groovy condition in the editor, is used to read the request parameter "rq_action":
if (g_request.containsKey('rq_action'))
{
def l_strAction = g_request.get('rq_action')
switch(l_strAction)
{
case "release":
return [releasePressed]
case "notReleased":
return [releaseNotPressed]
}
}
If the request parameter contains the value "release", the connection ID "releasePressed" will be generated using the return command. If the value is "notReleased", the connection ID "releaseNotPressed" is generated.
The connection ID is entered in the properties dialog of the respective branch. The name for a connection ID is freely definable but must always start with a lower-case letter.
In the subsequent process step, a Data group action is used to set or cancel the released status. This is done using a user-defined, static Boolean value that has the value "true" or "false", depending on the branch, and is assigned to the "Release" data field.
All of the connection IDs defined in the Groovy condition must be included in the process as outcomes of the condition, otherwise this can lead to an error in the process execution.