Skip to content
ralphhanna edited this page Dec 18, 2023 · 4 revisions

Table of Contents

Instance Data

Instance Data can be manipulated in several ways:

As Input to Engine calls

    const input={ model: 'Thunderbird', needsRepairs: false, needsCleaning: false };
    response = await engine.invoke({items: { id: itemId } }, input );

Expressions

keeping in mind that the bpmn definition defines conditional flow as such:
    <bpmn:sequenceFlow id="flow_gw1_clean" sourceRef="gateway_1" targetRef="task_clean">
      <bpmn:conditionExpression xsi:type="bpmn:tExpression"><![CDATA[
      (this.needsCleaning=="Yes")
      ]]></bpmn:conditionExpression>
    </bpmn:sequenceFlow>

Part of Script and Service Task

    <bpmn2:scriptTask id="task_reminder" name="Issue Reminder">
      <bpmn2:incoming>SequenceFlow_1h10gv4</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_0cokf0m</bpmn2:outgoing>
      <bpmn2:script><![CDATA[
            let data = this.token.data;
            console.log("sending a reminder scirpt");
            console.log(data);
            
            if (typeof data.reminderCounter === 'undefined') {
              data['reminderCounter']=0;
            }            
            
            data['reminderCounter']=data['reminderCounter']+1;
            this.token.log('testing from the inside: ');
      ]]></bpmn2:script>
    </bpmn2:scriptTask>

AppDelegate

Similar to Script and Service AppDelegate can manupilate Instance data.

Script Extensions

Script Extensions are supported in release 1.1 and later, allowing you to add a script to any node.

In this example we are adding a script to bpmn:startEvent

    <bpmn:startEvent id="StartEvent_1ohx91b">
      <bpmn:extensionElements>
        <camunda:script event="start"><![CDATA[
        console.log("This is the start event");
          this.applyInput({records:[1,2,3]});
          console.log(this.data);
          console.log("This is the start event");]]></camunda:script>
      </bpmn:extensionElements>
      <bpmn:outgoing>Flow_18xinq3</bpmn:outgoing>
    </bpmn:startEvent>
    

Item Data

In Release 1.3.22 added item.vars to store any variables related to the item as follows

Setting item.vars

You can set item.vars Inside your service logic :

  async service1(input, context) {
  ...
  item.vars= input;
 ...
}

or by having an event-listener such as:

Item Vars Script

MongoDB:

As a result MongoDB stores item.vars image

Using findItems:

            query = { "data.caseId": caseId, "items.vars.param1": 'value1' };
            items = await server.dataStore.findItems(query);
            console.log('items count',items);

Data Scope

The entire execution will have one data scope object, shared among all nodes, except the following will have own item part of the data object

  • SubProcess
  • and Loops (Multi-instances)

Image description

However, for SubProcess and Loop elements a seperate scope

Image description Image description

Query on Data

You can use Instance data as part of your query for Instances or Items For Details on Query see Data Query

Input-Output Data

Input and output is used in the following scenarios:

  • Subprocess (input/output)
  • Service Tasks (input/output)
  • Call Tasks (input/output)
  • Throw Message/Signal (input)
  • Catch Message/Signal (output)

Input/Output using Scripts

variable description
item.data refers to Instance Data or the token data for multi-instance tokens
item.input refers to input variable into the called task/event
item.output is the output of the called task/event
    <bpmn2:serviceTask id="Activity_00ticbc" name="Add 2 Using scripts" implementation="add" camunda:delegateExpression="add">
        <bpmn2:extensionElements>
        <camunda:executionListener event="start">
          <camunda:script scriptFormat="JavaScript">

            item.input.v1=33;
            item.input.v2=25;

          </camunda:script>
        </camunda:executionListener>
        <camunda:executionListener event="end">
          <camunda:script scriptFormat="JavaScript">
            
            item.data.result2= item.output + 100;

          </camunda:script>
        </camunda:executionListener>
      </bpmn2:extensionElements>

Input/Output using Camunda Extension of Input/Output Parameter

    <bpmn2:serviceTask id="Task_0xh2iwa" name="service1" implementation="service1">
      <bpmn2:extensionElements>
        <camunda:inputOutput>
          <camunda:inputParameter name="repeat">item.data.count</camunda:inputParameter>
          <camunda:outputParameter name="sequence">this.output.seq</camunda:outputParameter>
          <camunda:outputParameter name="returnText">'out text:'+this.output.text</camunda:outputParameter>
        </camunda:inputOutput>
      </bpmn2:extensionElements>
  • parameter name is the name of variable
  • value is a JavaScript expression

| Scenario | before call | caller Syntax| after call| |--|--|--|--|--| | Throw Msg| parameters.var1= '123';
output.var1 | throw(msg,parameters)| - | | Catch Msg| - | catch(msg,parameters)| data.var1= parameters.var1;| | Call Process| parameters.var1= '123'; | result=call(parameters)|data.var1= result.var1; | | Service Call | parameters.var1= '123'; | result=call(parameters)| data.var1= result.var1;| | Start Event| -| start(parameters)| data.var1= parameters.var1;
data.var1=input.var1;|

  • Call specs:

      input:
          var1    ->  data.myVar1
          var2    ->  5
    
      output:
          scenario 1:
          result  ->  <nothing>
          scenario 2:
          result  ->  output.result
    

    on-entry: item.input.var1= 51;

    on-run: item.output=call fun(item.input)

    on-exit:

      scenario 1:
      data.result  = item.output;
      scenario 2:
      data.result  = item.output.result;
    
  • Throw

    specs:

    output:

          caseId  ->  data.caseId
    

    on-entry:

       item.output.caseId= data.caseId;
    

    on-call:

      throw (signal,item.output)
    
  • Catch

    specs: none

    start trigger:

          data.caseId=input.caseId;
    
  • Start

    specs: none

    start trigger:

          data.caseId=input.caseId;
    
Clone this wiki locally