Workflow scripting
Scripts are used to perform automatic actions and fine-tune the behavior of the workflow. There are two basic types of scripts:
- Visibility scripts are executed to control the availability of the activity.
- Regular scripts are executed when a certain action is performed or event takes place.
In addition, some elements and adornments have scripts with special purposes, as for example the decision script which determines the exit which a case takes when running through a decision node.
There are two ways of managing scripts:
- Using embedded scripts: Embedded scripts are provided directly in the workflow editor, i.e., you open the script editor for the desired element, type the script content and save the script.
- Using scripts of the type Workflow*: Workflow scripts are saved on the Scripts page of the Web Admin Suite, see Scripts of the type Workflow. They can be referenced in an embedded script, i.e., you create an embedded script which executes a workflow script:
scriptExecutionService.execute("myscript.groovy")
The following table shows a comparison between both modes:
| Mode | Description | Advantages | Disadvantages |
|---|---|---|---|
| Embedded script | The complete script content is provided in the workflow editor. |
|
|
| Workflow script | The script is saved as a script of the type Workflow on the Scripts page. The embedded script references this workflow script. |
|
|
Scripts are written in Groovy. Since Groovy code runs in the Java Virtual Machine, you can also write Java code. Groovy code allows you to use dynamic typing, and to omit getter and setter methods, thus providing a shorter syntax. The following table shows some examples of the differences between Groovy and Java:
| Goal | Groovy | Java |
|---|---|---|
| Retrieve the subject of a case | def mysubject = ticket.subject | String mysubject = ticket.getSubject(); |
| Retrieve the main contact of a case | def mymaincontact = ticket.mainContact | Unit mymaincontact = ticket.getMainContact(); |
| Retrieve the value of a certain case field from a case | def myprio = ticket.get("helpdesk_fields.prio") | String myprio = ticket.get("helpdesk_fields", "prio"); |
| Set the subject of a case | ticket.subject = "asd" | ticket.setSubject("asd"); |