Tips & Tricks - Groovy Conditions in the Process

In the "Processes" module, conditions can be controlled using Groovy, allowing the system to respond to request values, among other things. In the sample application—which you can download here starting with Intrexx version 12.0.0 and import as usual using the process included with it—clicking a button triggers a release and saves the data record. Another button, the "Unlock" button, removes the lock and also saves the record.

The included process is disabled during import. To test the sample application, activate the process after importing it.

In the sample application, the "Share" button is configured with the "Save" action and the "rq_action" parameter. "rq_action" is set to the static value "release".

The "Unlock" button is also configured using the "Save" action and the "rq_action" parameter. rq_action is assigned the static value "notReleased" here.

During the process, the data group event handler responds to the insertion or modification of the record.

The Groovy script entered in the Groovy condition's properties dialog in the editor is used to read the "rq_action" request parameter:

            
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 return statement generates the connection ID "releasePressed." When the value is "notReleased," the connection ID "releaseNotPressed" is generated.

The connection ID is entered in the Properties dialog box for the respective branch. The name of a connection ID can be anything, but it must always begin with a lowercase letter.

In the next step of the process, a data group action is used to set or clear the release status. To do this, a user-defined, static Boolean value is used, which takes the value "true" or "false" depending on the branch and is assigned to the "Approval" data field.

All connection IDs defined in the Groovy condition must also be included in the process as outputs of the condition; otherwise, an error may occur during process execution.