Skip to main content

Script Task

Introduction

Script Task

info

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.

note

To use JavaScript as a scripting language, it is required to have a JavaScript scripting engine on the classpath. For Java 8 and 11 the Nashorn Engine is included by default. In case you are running a new Java version (e.g. 17) and you are using a customization project, you need to add the dependency manually:

<dependency>
<groupId>org.openjdk.nashorn</groupId>
<artifactId>nashorn-core</artifactId>
</dependency>

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);

Properties

:::palette-item com.flowable.design:flowable-core-palette com/flowable/palette/core.process.palette ScriptTask