Script Task

Script Task
A Script Task is executed by a business process engine. The modeler or implementer defines a script in a language that the engine can interpret. When the Task is ready to start, the engine will execute the script. When the script is completed, the Task will also be completed.
— BPMN 2.0.2 Standard, 10.3.3, Script Task

In Flowable, Script Tasks are used to execute scripts in a JSR-223 compatible scripting language, for instance JavaScript or Groovy.

Scripts Tasks are mainly used to perform simple calculations or operations. For more complex use cases, you should consider writing a Java Service and calling it via a Service Task.

Example

In the following example, a user is prompted to enter the first and last name. A script generates an email address and stores it in the variable "email":

Script Task

The following script shows a very simple example script that could be used to achieve this task:

var firstName = execution.getVariable("firstName").toLowerCase();
var lastName = execution.getVariable("lastName").toLowerCase();
var email = firstName + "." + lastName + "@yourCompany.com";
execution.setVariable("email", email);

Attributes

Group Attribute Description

General

ID

The unique identifier of the element within the process model.

Name

The name of the element. This is the name displayed in the diagram.

Documentation

A description and additional information about this element.

Details

Asynchronous

When enabled, the activity is started as an asynchronous job. The process state is persisted before this element is executed. Then the process execution is resumed asynchroneously. This can be used when the execution of an activity takes a long time to return the user interface. However, if an error occurs before the following wait state, there is no direct user feedback.

Auto store variables

Automatically stores any variable defined in the script on the execution. Please note that some languages such as JavaScript do not support this feature.

Script

Script that is executed when the task is executed.

Script format

Defines the script format. The script format must be provided if a script is provided. By default, Groovy and JavaScript are provided.

Execution listeners

Active Execution Listeners of the activity. This lets you react to the following events:

  • Start: Occurs when the activity is started.

  • End: Occurs when the activity is completed.

Skip expression

Defines an expression which is evaluated before executing the task. If it evaluates to true, the task is skipped.

Skip expressions are only be evaluated if there is a process variable _ACTIVITI_SKIP_EXPRESSION_ENABLED with the boolean value true.

Is for compensation

Determines whether the activity can serve as a compensation for another activity.

Multi instance

Multi instance type

Determines if multiple instances of this activity are created. There are three choices:

  • None (default, only one instance is created).

  • MI parallel (activities are created in parallel. This is a good practice for User Tasks).

  • MI sequential (activities are created sequentially. This is a good practice for Service Tasks).

Once a type other than None is chosen, the following options appear:

  • Collection: The number of instances is determined by the elements of a collection. For each element in the collection, a new instance is created.

  • Element variable: The variable under which each element is available to the newly created instance.

  • Element index variable: The variable under which the current number of iterations is stored.

  • Completion condition: An expression which, if it evaluated to true, stops the creation of new instances.

  • Cardinality: An expression or numeric value (integer) which determines how many instances are created.

Visual

Font weight

The font weight of the element in the diagram.

Font size

The font size of the element in the diagram.

Font color

The font color of the element in the diagram.

Font style

The font style of the element in the diagram.

Background color

The background color of the element in the diagram.

Border color

The border color of the element in the diagram.