JavaScript actions

Use a JavaScript action (Script task) to execute JavaScript code during workflow execution.

Signavio Workflow Accelerator runs the code on the server, using Node.js. This means that you can use ECMAScript 2015 (ES6) features.

As well as Node.js’ JavaScript API, scripts can use additional JavaScript libraries.

JavaScript action configuration

After creating or selecting a JavaScript action, the configuration panel looks like this:

JavaScript configuration panel
JavaScript configuration panel

The top section of the panel contains the JavaScript text editor. By default, it already contains console.log('Hello World!'). Use the console API for log output when testing scripts.

Using process variables

Next, we'll show how to work with data. Suppose that the process includes a form that has each type of field and looks like this:

Form fields that declare process variables
Form fields that declare process variables

On the JavaScript configuration panel, the Add existing variable pick list now shows the form field variables.

Process variable selection
Process variable selection

Select the variables you want to access in the script. The script can access the variables using the JavaScript variable name from the Variables table. To access object variables’ fields, use the field names specified for the corresponding data type: Case, Email, File or User.

You see all available fields after entering the variable name and . .

In this example (below), you have selected all variables. For each variable that you select, you get an input field to specify a test value. Here you see all fields with a test value.

JavaScript test values
JavaScript test values

Clicking Start new test again to see the JSON structure of the variable data for the different variable types.

JavaScript JSON values
JavaScript JSON values

The contract and salesRepresentative variables have complex types, File and User, so the table only shows an ID. The Updated value column shows the result of assigning new values to these variables in the script.

Update process variables

You can use JavaScript actions to update process variables. Make sure you re-assign a new value to the variable instead of mutating the variable itself. Otherwise, the system will ignore the update. For example, the system ignores contactEmails.push('joan.doe@example.org'), but correctly processes contactEmails = [].concat([], 'joan.doe@example.org'). This restriction doesn't apply to variables you only use in the context of the JavaScript action.