bpmnServer / bpmn-server

BPMN 2.0 server for Node.js , providing modeling, execution, persistence and monitoring for Workflow. along with sample UI. Intended to be developers workbench for BPMN 2.0
MIT License
186 stars 48 forks source link

Tasks of multi-instance SubProcess do not know their associated data value #178

Closed kvdinker closed 8 months ago

kvdinker commented 8 months ago

Hi,

I´m currently working on a workflow with multi-instance subprocesses, where we have some usertasks inside the subprocess which need to access their associated collection value. But unfortunately I only find one subprocess related object with all values in the datastore and no key that tells which element belongs to the current subprocess.

image

Is there any way to access the subprocess related value?

Setup:

If you need further information, let me know. Thanks

ralphhanna commented 8 months ago

Can you please attach your model bpmn file, Thanks

kvdinker commented 8 months ago

@ralphhanna, sure I will add a short example below: multi-instance SubProcess

I discovered an additional related problem in this example. It looks like the form fields of the "Create Vote" task are stored in the subprocess layer and not in the related multi-instance. Therefore those values are overwritten in every multi-instance.

image

Code:

<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="sample-diagram" targetNamespace="http://bpmn.io/schema/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
  <bpmn2:process id="Process_1" isExecutable="false">
    <bpmn2:startEvent id="StartEvent_1">
      <bpmn2:outgoing>Flow_1ly2dyb</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:sequenceFlow id="Flow_1ly2dyb" sourceRef="StartEvent_1" targetRef="Activity_1aw4w97" />
    <bpmn2:sequenceFlow id="Flow_0gxv496" sourceRef="Activity_1aw4w97" targetRef="department" />
    <bpmn2:scriptTask id="Activity_1aw4w97" name="Provide Departments" scriptFormat="JavaScript">
      <bpmn2:incoming>Flow_1ly2dyb</bpmn2:incoming>
      <bpmn2:outgoing>Flow_0gxv496</bpmn2:outgoing>
      <bpmn2:script>item.data.departments = ["IT", "HR", "Billing"]</bpmn2:script>
    </bpmn2:scriptTask>
    <bpmn2:sequenceFlow id="Flow_1umlt4b" sourceRef="department" targetRef="Activity_1mx9fl7" />
    <bpmn2:endEvent id="Event_1jag0kh">
      <bpmn2:incoming>Flow_0ri93gq</bpmn2:incoming>
    </bpmn2:endEvent>
    <bpmn2:sequenceFlow id="Flow_0ri93gq" sourceRef="Activity_1mx9fl7" targetRef="Event_1jag0kh" />
    <bpmn2:userTask id="Activity_1mx9fl7" name="Summerize Votes">
      <bpmn2:incoming>Flow_1umlt4b</bpmn2:incoming>
      <bpmn2:outgoing>Flow_0ri93gq</bpmn2:outgoing>
    </bpmn2:userTask>
    <bpmn2:subProcess id="department" name="Department">
      <bpmn2:incoming>Flow_0gxv496</bpmn2:incoming>
      <bpmn2:outgoing>Flow_1umlt4b</bpmn2:outgoing>
      <bpmn2:multiInstanceLoopCharacteristics camunda:collection="$(item.data.departments)" />
      <bpmn2:startEvent id="Event_03fca9f">
        <bpmn2:outgoing>Flow_1l3c0w1</bpmn2:outgoing>
      </bpmn2:startEvent>
      <bpmn2:endEvent id="Event_1evbsib">
        <bpmn2:incoming>Flow_05e3vg6</bpmn2:incoming>
      </bpmn2:endEvent>
      <bpmn2:userTask id="Activity_1a3s9ce" name="Create Vote">
        <bpmn2:extensionElements>
          <camunda:formData>
            <camunda:formField id="vote" label="Vote" type="boolean" defaultValue="false" />
            <camunda:formField id="additionalInformation" label="additional Information" type="string" />
          </camunda:formData>
        </bpmn2:extensionElements>
        <bpmn2:incoming>Flow_0m5apq3</bpmn2:incoming>
        <bpmn2:outgoing>Flow_05e3vg6</bpmn2:outgoing>
      </bpmn2:userTask>
      <bpmn2:scriptTask id="Activity_0svucn5" name="Read Department" scriptFormat="JavaScript">
        <bpmn2:incoming>Flow_1l3c0w1</bpmn2:incoming>
        <bpmn2:outgoing>Flow_0m5apq3</bpmn2:outgoing>
        <bpmn2:script>console.log((item.data));</bpmn2:script>
      </bpmn2:scriptTask>
      <bpmn2:sequenceFlow id="Flow_1l3c0w1" sourceRef="Event_03fca9f" targetRef="Activity_0svucn5" />
      <bpmn2:sequenceFlow id="Flow_05e3vg6" sourceRef="Activity_1a3s9ce" targetRef="Event_1evbsib" />
      <bpmn2:sequenceFlow id="Flow_0m5apq3" sourceRef="Activity_0svucn5" targetRef="Activity_1a3s9ce" />
    </bpmn2:subProcess>
  </bpmn2:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
      <bpmndi:BPMNEdge id="Flow_1ly2dyb_di" bpmnElement="Flow_1ly2dyb">
        <di:waypoint x="448" y="258" />
        <di:waypoint x="520" y="258" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0gxv496_di" bpmnElement="Flow_0gxv496">
        <di:waypoint x="620" y="258" />
        <di:waypoint x="700" y="258" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1umlt4b_di" bpmnElement="Flow_1umlt4b">
        <di:waypoint x="1200" y="258" />
        <di:waypoint x="1260" y="258" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0ri93gq_di" bpmnElement="Flow_0ri93gq">
        <di:waypoint x="1360" y="258" />
        <di:waypoint x="1392" y="258" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="412" y="240" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1trqr8z_di" bpmnElement="Activity_1aw4w97">
        <dc:Bounds x="520" y="218" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1jag0kh_di" bpmnElement="Event_1jag0kh">
        <dc:Bounds x="1392" y="240" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1oo3z2k_di" bpmnElement="Activity_1mx9fl7">
        <dc:Bounds x="1260" y="218" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0dsqa5j_di" bpmnElement="department" isExpanded="true">
        <dc:Bounds x="700" y="139" width="500" height="211" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_1l3c0w1_di" bpmnElement="Flow_1l3c0w1">
        <di:waypoint x="778" y="260" />
        <di:waypoint x="820" y="260" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_05e3vg6_di" bpmnElement="Flow_05e3vg6">
        <di:waypoint x="1070" y="260" />
        <di:waypoint x="1132" y="260" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0m5apq3_di" bpmnElement="Flow_0m5apq3">
        <di:waypoint x="920" y="260" />
        <di:waypoint x="970" y="260" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="Event_03fca9f_di" bpmnElement="Event_03fca9f">
        <dc:Bounds x="741.6666666666666" y="242" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1evbsib_di" bpmnElement="Event_1evbsib">
        <dc:Bounds x="1132" y="242" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_05zd5q5_di" bpmnElement="Activity_1a3s9ce">
        <dc:Bounds x="970" y="220" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1i5cr6k_di" bpmnElement="Activity_0svucn5">
        <dc:Bounds x="820" y="220" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn2:definitions>
ralphhanna commented 8 months ago

Thanks for your submission, a fix is on the way the correct data structure should be:

{
  departments: [ 'IT', 'HR', 'Billing' ],
  department: {
     IT: { seq: 0, customVar: 'set by script' },
    HR: { seq: 1, customVar: 'set by script', MyVote: 'HR' },
    Billing: { seq: 2, customVar: 'set by script' }
  }
}

Where 'v1','v2','v3' is what I entered in the user prompt.

I expect new release later this week.

Thanks

kvdinker commented 8 months ago

Thanks for the quick solution. How do I recognize which task is responsible for which department? All department objects are contained in the IItemData of the individual tasks.

In the same example, I have seen that the main workflow continues to run when a subprocess is completed and the process has not waited for all subtasks. Is it due to a misconfiguration of the bpmn file or how can I achieve this behavior? image

ralphhanna commented 8 months ago

Yes, that is what I am working on right now.

ralphhanna commented 8 months ago

New Release 2.1.5 is now ready. Please see https://github.com/bpmnServer/bpmn-server/blob/master/docs/examples/loop.md for details about loops