Skip to main content

Working with Workflow Variables

Generally there are 4 ways workflow variables can be set:

Set within the process start

When starting a workflowinstance by key / signal you can pass your variables there.

When you start those directly via the methods, ensure that you also pass the targetId and targetContext variable to the process. Starting a workflow via signals defined in the ADITO Context or starting them by hand via the 'start workflow' Action, both the targetId and targetContext variables are set by default.

var workflowVariables = {
targetId: vars.getString("$local.uid"),
targetContext: ContextUtils.getCurrentContextId(),
myVariable: "foo"
}

workflow.startProcessByKey("SalesProjectPhaseExecution", workflowVariables);

Set via Service Task

In a Service Task the variables defined by a workflow are available via the system variable $local.value as a JSON String

var variables = JSON.parse(vars.get("$local.value"));
//...

The variables in a JDito service task are set via the method result.object(). The passed parameter will be added to the defined variables.

var variables = JSON.parse(vars.get("$local.value"));
var activityId = variables.activityId;

//function for getting a linked contacts of an activity
var contactsStr = getContactsLinkString(activityId);

var variablesToSet = {
"contactPersons": contactsStr,
"myServiceVariable": "foo"
}

result.object(variablesToSet);

Parameters which can be set in a Service Task are also available as workflow variables. But only when the process has reached the Service Task. The defined parameter are available in its context.

Set via Script Task

Script Tasks are used to perform small calculations within the workflow. Variables can be also set in those. Here you can use the method execution.setVariable(variableName, value). For example the following Javascript Script Task calculates a due date and provides it as a variable:

var monthToAdd = parseInt(execution.getVariable("CareDueMonth"), 10);

if(isNaN(monthToAdd))
monthToAdd = 0;

var date = new Date();
var newDate = new Date(date.setMonth(date.getMonth() + monthToAdd));

execution.setVariable("dueDate", newDate.toISOString());

Results of a form field

The input of a user can be provided as an variable to process the entered value.

WorkflowUserTask

Expression Flowable (the workflow engine) uses UEL for expression-resolving. UEL stands for Unified Expression Language and is part of the EE6 specification.

For example expressions can be used to determine a sequence flow.

The syntax of the UEL is very simple: (Assume, that we check at a exclusive Gateway if the user input was active)

${isActive == true}

While working with variables there are some practical Expression functions.

Instead of simply calling the variable, which will lead to an exception when the variable doesn’t exists, you can use following syntax:

${variables:get(isActive) == true}

Instead of using variables: you can also use var: or vars:

${vars:eq(isActive, true)}

More examples and available Methods can be found in the official Documentation.

But expressions can also be used to set values dynamically. For example:

ExpressionUserTask

In this User Task the assignment is set via an expression. Because in this use case a responsible user of a Salesproject should get the task assigned.

the Assignment field expects an userId.

The due date can be also set via an expression. In this example the date was calculated in a script task and passed as a variable. The vars:get alias is used to prevent errors. For example when the variable couldn’t be set.