Script task

A task that is executed by a business process engine to mainly perform simple calculations or operations. When the task is ready to start, the engine executes the script, and marks it as completed when the script has finished.

To configure script tasks, you must provide a script in Groovy language.

Because each script task is independent, include import statements for all the packages you are using in a script for each script task. Avoid using generic imports to reduce execution time.

Do not use script tasks to declare methods that a subsequent script task would use. Groovy compiles and temporarily caches the script at execution time. If you call the method in a subsequent script tasks:
  • The cached method might not be available anymore.
  • Even if the method is available, it retains the cached values of variables, which might lead to unexpected results.

Use the groovy-lib folder to store scripts that are common to a large number of tasks.

In the context of workflow script tasks, the <Resource>Api interfaces (such as AssetApi, CommunityTypeApi, FileApi, and so on) are already instantiated and accessible via <resource>Api variables (such as assetApi, communityTypeApi, fileApi, and so on).

Attributes: General

Attribute Description
Model ID The unique identifier of the element within the process model.
Name The name of the element displayed in the diagram.
Documentation A description and any additional information about this element.

Attributes: Details

Attribute Description
Script A script that is executed when the task is activated.

Attributes: Execution

Attribute Description
Asynchronous When enabled, the activity starts as an asynchronous job.
Execution listeners

Allows you to invoke Java logic after certain events:

  • Start: Executes after the activity has been started.
  • End: Executes after the activity was completed.
  • Transition: When defined on a sequence flow, executes once the flow is transition is taken.
Skip expression

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

You must opt-in to enable this feature by setting a process variable _FLOWABLE_SKIP_EXPRESSION_ENABLED with the Boolean value true.

Attributes: Multi instance

Attribute Description
Multi instance type Determines if multiple instances of this activity are created:
  • None - default, only one instance is created.
  • MI parallel - activities are created in parallel. This is good practice for user tasks.
  • MI sequential - activities are created sequentially. This is good practice for service tasks.
Collection

Expression to set the loop collection for a multi-instance task. The number of instances is determined by the elements of a collection. For each element in the collection, a new instance is created.

A common use case is to loop over lists created by multi-element subforms. For example, if you bound a subform to an array of invoice positions using the expression invoicePositions, you can set the loop collection to ${invoicePositions} to loop over each position.

Element variable

The name of the variable where the currently processed item from the loop collection is stored, for example invoicePosition.

You can access the element in the process through an expression, for example ${invoicePosition}. To access the element in a form, you can add a task listener that copies the variable on creation from the execution level to a local task variable, for example ${task.setVariableLocal("invoicePosition",invoicePosition)}. The element is then available in the form through the task.invoicePosition variable.

Element index variable

The name of the variable where the index of the currently processed item from the loop collection is stored, for example, itemIndex.

The index starts with 0 and increases with every element that is being looped through. You can access the index in the process through an expression, for example ${itemIndex} in the process. To access the index in a form, you can add a task listener that copies the variable on creation from the execution level to a local task variable, for example ${task.setVariableLocal(&quot;itemIndex&quot;, itemIndex)}. The index is then available in the form through the task.itemIndex variable.

Cardinality A number or an expression that evaluates to an integer, which controls the number of activity instances that are created. If the attribute Collection is empty, a new instance is created for every element of the list. With cardinality, you can overwrite this and only create a given number of instances. You can also use this attribute if you want to loop over an activity a given number of times without specifying a collection.
Completion condition A Boolean expression that when true cancels the remaining activity instances, stopping the loop, and produces a token.

Attributes: Visual

Attribute Description
Font color The font color of the element in the diagram.
Font size The font size of the element in the diagram.
Font style The font style of the element in the diagram.
Font weight The font weight 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.