Workflow Variables

When working with Workflows there are two different types of variables available of which one comes in two variants:

JavaScript Variables - Normal JavaScript variables can be declared in business actions and conditions. The scope of these variables is limited to the action / condition where they are declared and they are only persisted during the execution of the action / condition.

Workflow Variables - Workflow variables are string variables defined in the Workflow Designer. The variables are global to the workflow instance and the values are stored on the object-in-workflow relation and thus persisted as long as this relation remains. Workflow variables come in two flavors, 'bound' and 'unbound'.

Bound Workflow Variables

A bound workflow variable is bound to a STEP Attribute and gets its validation from the STEP Attribute. Apart from getting the validation from a STEP Attribute, bound workflow variables also get the corresponding attribute editors when a user chooses to display them in workbench views (refer to the Views and Mappings for Workflows section of the Workflows documentation here).

Note: The attributes to bind to must be externally maintained, non-dimension dependent description attributes and should not be valid for any object types.

Unbound Workflow Variables

When a workflow variable is not bound to an attribute, it is a simple string variable with a default workbench view editor.

The value of unbound variables can be the result of an expression. In the expression panel, a reserved variable named 'value' is used. Below a script / expression is shown that will set the value of the variable to be the ID of the current node. Expressions are re-calculated each time the variable is used.

value = node.getID();

Creating a Workflow Variable

To create a workflow variable press the add icon and select Add Workflow Variable in the 'Workflow Variables/Attachments' section in the left side of the Designer.

This will bring up a dialog where the user can enter the ID of the variable and optionally select to bind it to an 'Attribute' or add an 'Expression'.

As noted in the Business Rules in Workflows section in the Workflows documentation, workflow variables are manipulated through the WorkflowInstance interface. Thus the value of a workflow variable can be obtained from a business action as follows:

var valueStoredInVariable = node.getWorkflowInstance(workflow).getSimpleVariable("Variable ID");

And likewise a simple value for a workflow variable could be set with:

node.getWorkflowInstance(workflow).setSimpleVariable("Variable ID", "Value to be set");

While the above applies to both bound and unbound variables, for bound variables a value object can be obtained. This can be done with:

var valueObj = node.getWorkflowInstance(workflow).getValue("ID of Attribute the variable is bound to");

Workflow Variables in Use

Consider a user group which consists of five users. All of these five users have access to a particular workflow, and can submit a product from the Edit to the Review state. For this workflow, because there is a requirement to identify which of these five users submitted a particular product, a business rule has been set up to save the details to an attribute. This business action is set on the desired state in the State Editor on the 'On Exit' tab. In this case it is on the Edit sate.

To create this business rule, a workflow variable first needs to be defined, which is 'Released by' for this workflow.

Then a business rule needs to be written to call the workflow variable as mentioned below:

var assigneeID = step.getCurrentUser().getID();
node.getWorkflowInstance(workflow).setSimpleVariable("Variable ID", assigneeID);

Note: In this formula, "Variable ID" should be replaced with the ID of the actual workflow variable for the workflow in use.

With this business action in place, when a product is submitted, the business rule is executed and the user ID of the user who submitted the product is stored. This is visible in the STEP Workflow Items tab if this was mapped in the views and mappings View Editor.

For more on setting up views and mappings, refer to the Views and Mapping for Workflows topic in the Workflows documentation here.

Workflow Variables in Web UI

Workflow variables are also supported in Web UI, where they can be added to relevant components using the Workflow Variable or Workflow Variable Header components. In addition, workflow variables can be added to submit actions (Submit Action or Submit from Grid Action).