Scripts are used to execute a script as part of a process. Process variables can be passed to the script and the results of a script can be sent back to a process instance as process variables.
Scripts are added to a process definition using a script task.
The basic properties of a script are:
|Script name||Required. The name of the script. Must be in lowercase and between 1 and 26 characters in length. Alphanumeric characters and hyphens are allowed, however the name must begin with a letter and end alphanumerically, for example
|Language||Required. The development language the script is written in, for example
|Script description||Optional. A description of what the script should be used for, for example
Create a script
To create a script:
Sign into the Modeling Application and open a project.
Click the NEW dropdown.
Select how to create the script:
Create > Script creates a new, empty script.
Upload > Script allows for uploading an existing script
.binfile into the Modeling Application.
Alternatively use the + or Upload buttons next to Scripts in the left-hand menu.
Enter a name and optional description.
The Modeling Application contains two tabs for creating and managing scripts.
The Script Editor is the GUI for modeling scripts by typing in the declared language. The Metadata contains the properties related to the script.
Once a script has been written, it can be simulated by entering potential inputs and viewing their output.
In the UI click the Simulate button after entering the input values to simulate. The results will be populated in the outputs section.
There are two types of variables associated with a script. Script variables are stored as JSON and are used to pass values between a process and a script. Declared variables are used within the script body itself.
Script variables can be used to pass and receive values from process variables.
The properties for a script variable are:
|name||A unique name that can contain alphanumeric characters and underscores but must begin with a letter, for example
|type||A data type selected from a dropdown. See the following table for a list of data types, for example
|required||Sets whether the script variable must contain a value when the task is started, for example
|value||An optional default value for the script variable, for example
The data types that a script variable can be set as are:
|String||A sequence of characters, for example
|Integer||A positive whole number, for example
|Boolean||A value of either
|Date||A specific date in the format
|Datetime||A specific date and time in the format
|File||A file uploaded into a process definition or as part of a process instance or task|
|JSON||A JSON object, for example
|Folder||A folder object described as JSON, for example
|Array||A comma separated list of entries, for example
Declared variables are used within the script itself and can be set to the value of a script variable by using the prefix
variables. to reference the script variable. An input variable will set a declared variable to the value of a script variable when the script is executed.
For example, in a process the script variables
orders will have their values set from process variables. The declared variables
numberOfOrders can then be set to these values using the following:
let costOfItem = variables.cost; let numberOfOrders = variables.orders;
The value of the script variable
totalCost will then be set after the script has executed by using the following:
variables.totalCost = costOfItem * numberOfOrders;
The value of the script variable
totalCost can finally be sent back to the process by mapping it to a process variable.
Scripts can be used to start a process instance by building a payload.
For example, use the process definition ID and set the process variables using:
let startProcessInstanceCmd = processPayloadBuilder.start() .withProcessDefinitionKey("Process_GyW7Ekkw") .withVariable("orderNumber": variables.orderNumber) .withVariable("quantity": variables.quantity) .build(); commandProducer.send(startProcessInstanceCmd);
The actions that can be run against a script are:
|Download script||Download the bin file for the script.|
|Validate||Run validation against the script. Any errors can be seen in the log history at the bottom of the Modeling Application and are flagged in a pop-up box.|
|Save||Save any changes made to the script.|
|Delete||Delete the script.|