Skip to content

step variables

mandeep6ill edited this page Nov 23, 2017 · 1 revision

Step Variables:

Step Variables are flowObject level variables defined while designing the workflow. These variables are only accesible inside the flowObject and will not propogate through out the process.

Types of Step Variables

While designing the workflow, one can define step variables at each flow Object, in InputOutput paramter tab of the modeler. Each step variable can be any of the following three types:

  • String
  • List
  • Map

After defining the step Variables for a flowObject, we can use it inside the flowObject to create dynamically evaluated expressions. All the defined step variables are pushed into _msg json object. So, these variables need to accessed via _msg. prefix with the variable name. Any variable which needs to be dynamically evaluated can be written as a javascript expression inside string template - ${ }. Examples are provided for each variable type including a string which is an expression. All the process Variables and incoming message variables from previous flow objects are accessible in the expressions without any prefixes

Note: The values/keys inside List and Map object will not be evaluated.

Example 1

Take a workflow with a script Task, and define the following step variables :

   input1 : "Ouput1"  - String
   input2 : "${23+34+(72*60)}"  - String (JS Expression)
   input3 : [1,2,3,4] - List
   input4 : {'a' : 'b', 'c':'d'} - Map

Once you define these step variables inside your script task with _msg. prefix, you can access them in writing your script, for examples:

    if (_msg.input1 === 'Output1') {
        var evalInput2 = _msg.input2;
        _msg.input4['a'] = _msg.input3[2];
    }

Example 2

Suppose in a workflow, you want to modify and use a value, which is an output of some other flowObject(eg. ServiceTask or Business Rule Task), you cannot modify the value unless it is a script task. So, whenever there is a need for modification of some variable, a script task is necessary. With the introduction of step variables, you can directly modify or evaluate the variables obviating the need for explicit script task.

WorkAround for the Modeler:

Currently, We support defining the step variables for business rule task only. If you want to define for other flow objects like scripttask, servicetask or usertask, we need to edit the bpmn file and add the following XML stub under a flow object :

<bpmn2:extensionElements>
        <camunda:inputOutput>
          <camunda:inputParameter name="input1">output1</camunda:inputParameter>
          <camunda:inputParameter name="input2">${300*8+9*(90+99)}</camunda:inputParameter>
          <camunda:inputParameter name="input3">
            <camunda:list>
              <camunda:value>1</camunda:value>
              <camunda:value>2</camunda:value>
              <camunda:value>awesome</camunda:value>
            </camunda:list>
          </camunda:inputParameter>
          <camunda:inputParameter name="input4">
            <camunda:map>
              <camunda:entry key="key1">val1</camunda:entry>
              <camunda:entry key="key2">val2</camunda:entry>
            </camunda:map>
          </camunda:inputParameter>
        </camunda:inputOutput>
      </bpmn2:extensionElements>

This XML snippet contains, four input variables, each of a different kind. The first input1 is of String type, second input2 is of String type but a javascript expression which will be evaluated, third and fourth are input3 which is of List type and input4 which is of Map type, respectively.

Example of the workaround:

The following XML snippet is the part of a flowObject in a bpmn file without Step Variables:

<bpmn2:scriptTask id="ScriptTask_01geqa7" name="ScriptTask">
      <bpmn2:incoming>SequenceFlow_0a6mcrh</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_04rt3gb</bpmn2:outgoing>
      <bpmn2:script><![CDATA[if(_msg.input1 === 'output1') {
                                var list = _msg.input4;
                                var map = _msg.input5;
                                map.key1 = list[1];
                                }]]></bpmn2:script>
      </bpmn2:scriptTask>

Edited snippet of the bpmn file for the above sepcified flow object to add step variables:

<bpmn2:scriptTask id="ScriptTask_01geqa7" name="ScriptTask">
      <bpmn2:incoming>SequenceFlow_0a6mcrh</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_04rt3gb</bpmn2:outgoing>
      <bpmn2:script><![CDATA[if(_msg.input1 === 'output1') {
                                var list = _msg.input4;
                                var map = _msg.input5;
                                map.key1 = list[1];
                                }]]></bpmn2:script>
                                
      <bpmn2:extensionElements>
        <camunda:inputOutput>
          <camunda:inputParameter name="input1">output1</camunda:inputParameter>
          <camunda:inputParameter name="input2">${300*8+9*(90+99)}</camunda:inputParameter>
          <camunda:inputParameter name="input4">
            <camunda:list>
              <camunda:value>1</camunda:value>
              <camunda:value>2</camunda:value>
              <camunda:value>awesome</camunda:value>
            </camunda:list>
          </camunda:inputParameter>
          <camunda:inputParameter name="input5">
            <camunda:map>
              <camunda:entry key="key1">val1</camunda:entry>
              <camunda:entry key="key2">val2</camunda:entry>
            </camunda:map>
          </camunda:inputParameter>
        </camunda:inputOutput>
      </bpmn2:extensionElements>
      
    </bpmn2:scriptTask>