Tips & Tricks - Groovy conditions in a process

In the Processes module, conditions can be controlled using Groovy and can therefore respond to request values, among other things. In the sample application, which you can download here and import as usual with the included process, we want to trigger a release by clicking on a button and save the record. 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 sample application, the "Release" button is configured with the "Save" action type and the "rq_action" parameter. rq_action is given the static value "release".

The "Cancel release" button is also configured with the "Save" action type and the "rq_action" parameter. rq_action is given the static value "notReleased".

In the process, the data group event handler responds to the addition or modification of the record.

Using Groovy script entered in the properties dialog of the Groovy condition in the editor, the request parameter rq_action is read:


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.