-
Notifications
You must be signed in to change notification settings - Fork 60
Data
ralphhanna edited this page Dec 18, 2023
·
4 revisions
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 );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> <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>Similar to Script and Service AppDelegate can manupilate Instance data, however AppDelegate are stateless.
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>
The entire execution will have one data scope object, shared among all nodes except SubProcess and Loops (Multi-instances), each will have own item part of the data object

However, for SubProcess and Loop elements a separate scope

For Details on Query see Data Query