Camunda call external sub process (Call Activity) example

Camunda subprocesses can be implemented in two ways: Embedded Subprocess and Call Activity. The following describes the implementation of camunda external sub process (Call Activity). Through examples, it introduces how the main process initiates the sub process and how the variables between the main sub processes are transferred.

1, What is a call subprocess

BPMN 2.0 distinguishes between embedded subprocesses and call activities. Conceptually, when the process execution reaches the activity, both will invoke the subprocess.

The difference is that the calling activity refers to a process outside the process definition, while the sub process is embedded in the original process definition. The main use case for invoking activities is to have a reusable process definition that can be invoked from multiple other process definitions. The process definition of a subprocess is resolved at run time. If necessary, sub processes can also be called independently.

When the process execution reaches the calling activity, a new process instance will be created, which is used to execute the sub process. Parallel sub execution may be created as in a regular process. The main process instance will wait until the sub process is completely completed, and then continue with the original process.

2, Process simulation verification

Simulated document processing process: the drafter drafts the document - Department countersignature - leader signing, in which the Department countersignature is realized through an external sub process.

Step 1: design flow chart

Main process of design document approval:

Design document countersignature sub process:

Step 2. Main sub process Association configuration

Click the sub process node to configure which sub process to call. In the calling activity, the calledElement property contains the process definition key as a reference to the sub process. This means that the latest process definition version of the subprocess is always called. To invoke another version of the subprocess, you can define the properties calledElementBinding, calledElementVersion, and calledElementVersionTag in the invocation activity. These properties are optional.

Step 3: main and sub process variable transfer configuration

You can pass process variables to subprocesses and vice versa. The data is copied to the child process at startup and back to the main process at the end.

As shown in the figure below, define the main process variables a1 and a2 to be passed to sub processes b1 and b2 respectively.

As shown in the following figure, define the sub process variable c1 to be passed to the main process c2.

As shown in the following figure, the variable c1 is generated through script simulation in the sub process, and the form fields can be passed in the actual business application.

Main process BPMN process model document:

<?xml version="1.0" encoding="UTF-8"?>

<bpmn:definitions xmlns:bpmn="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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_031zkxq" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.8.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">

  <bpmn:process id="Process_0z2exxd" name="Document approval process" isExecutable="true">

    <bpmn:startEvent id="StartEvent_1">

      <bpmn:outgoing>Flow_0zm80xb</bpmn:outgoing>

    </bpmn:startEvent>

    <bpmn:sequenceFlow id="Flow_0zm80xb" sourceRef="StartEvent_1" targetRef="Activity_1wpmqyf" />

    <bpmn:sequenceFlow id="Flow_0go3jlb" sourceRef="Activity_1wpmqyf" targetRef="Activity_1yu8lt7" />

    <bpmn:sequenceFlow id="Flow_0tp93xf" sourceRef="Activity_1yu8lt7" targetRef="Activity_10emus5" />

    <bpmn:endEvent id="Event_1pnyryf">

      <bpmn:incoming>Flow_036jxrf</bpmn:incoming>

    </bpmn:endEvent>

    <bpmn:sequenceFlow id="Flow_036jxrf" sourceRef="Activity_10emus5" targetRef="Event_1pnyryf" />

    <bpmn:callActivity id="Activity_1yu8lt7" name="Department countersignature" calledElement="Process_0fqoao8">

      <bpmn:extensionElements>

        <camunda:in source="a1" target="b1" />

        <camunda:in source="a2" target="b2" />

        <camunda:out source="c1" target="c2" />

      </bpmn:extensionElements>

      <bpmn:incoming>Flow_0go3jlb</bpmn:incoming>

      <bpmn:outgoing>Flow_0tp93xf</bpmn:outgoing>

    </bpmn:callActivity>

    <bpmn:userTask id="Activity_10emus5" name="Issued by leaders" camunda:assignee="demo">

      <bpmn:incoming>Flow_0tp93xf</bpmn:incoming>

      <bpmn:outgoing>Flow_036jxrf</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:userTask id="Activity_1wpmqyf" name="Official document drafting">

      <bpmn:incoming>Flow_0zm80xb</bpmn:incoming>

      <bpmn:outgoing>Flow_0go3jlb</bpmn:outgoing>

    </bpmn:userTask>

  </bpmn:process>

  <bpmndi:BPMNDiagram id="BPMNDiagram_1">

    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0z2exxd">

      <bpmndi:BPMNEdge id="Flow_036jxrf_di" bpmnElement="Flow_036jxrf">

        <di:waypoint x="690" y="117" />

        <di:waypoint x="752" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0tp93xf_di" bpmnElement="Flow_0tp93xf">

        <di:waypoint x="530" y="117" />

        <di:waypoint x="590" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0go3jlb_di" bpmnElement="Flow_0go3jlb">

        <di:waypoint x="370" y="117" />

        <di:waypoint x="430" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0zm80xb_di" bpmnElement="Flow_0zm80xb">

        <di:waypoint x="215" y="117" />

        <di:waypoint x="270" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">

        <dc:Bounds x="179" y="99" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_1pnyryf_di" bpmnElement="Event_1pnyryf">

        <dc:Bounds x="752" y="99" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_1k4sxw6_di" bpmnElement="Activity_1yu8lt7">

        <dc:Bounds x="430" y="77" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_125gzjf_di" bpmnElement="Activity_10emus5">

        <dc:Bounds x="590" y="77" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_0ztm7d3_di" bpmnElement="Activity_1wpmqyf">

        <dc:Bounds x="270" y="77" width="100" height="80" />

      </bpmndi:BPMNShape>

    </bpmndi:BPMNPlane>

  </bpmndi:BPMNDiagram>

</bpmn:definitions>

Sub process BPMN process model file:

<?xml version="1.0" encoding="UTF-8"?>

<bpmn:definitions xmlns:bpmn="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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_10qlgev" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.8.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">

  <bpmn:process id="Process_0fqoao8" name="Official document countersignature sub process" isExecutable="true">

    <bpmn:startEvent id="StartEvent_1">

      <bpmn:outgoing>Flow_01enblh</bpmn:outgoing>

    </bpmn:startEvent>

    <bpmn:sequenceFlow id="Flow_01enblh" sourceRef="StartEvent_1" targetRef="Activity_1nkq50z" />

    <bpmn:endEvent id="Event_13q9iri">

      <bpmn:incoming>Flow_0ebh7be</bpmn:incoming>

    </bpmn:endEvent>

    <bpmn:sequenceFlow id="Flow_0ebh7be" sourceRef="Activity_1nkq50z" targetRef="Event_13q9iri">

      <bpmn:extensionElements>

        <camunda:executionListener event="take">

          <camunda:script scriptFormat="groovy">def c1 = "hello";

execution.setVariable("c1", c1);</camunda:script>

        </camunda:executionListener>

      </bpmn:extensionElements>

    </bpmn:sequenceFlow>

    <bpmn:userTask id="Activity_1nkq50z" name="jointly sign" camunda:assignee="user1">

      <bpmn:incoming>Flow_01enblh</bpmn:incoming>

      <bpmn:outgoing>Flow_0ebh7be</bpmn:outgoing>

    </bpmn:userTask>

  </bpmn:process>

  <bpmndi:BPMNDiagram id="BPMNDiagram_1">

    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0fqoao8">

      <bpmndi:BPMNEdge id="Flow_0ebh7be_di" bpmnElement="Flow_0ebh7be">

        <di:waypoint x="370" y="117" />

        <di:waypoint x="432" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_01enblh_di" bpmnElement="Flow_01enblh">

        <di:waypoint x="215" y="117" />

        <di:waypoint x="270" y="117" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">

        <dc:Bounds x="179" y="99" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_13q9iri_di" bpmnElement="Event_13q9iri">

        <dc:Bounds x="432" y="99" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_1m91lyj_di" bpmnElement="Activity_1nkq50z">

        <dc:Bounds x="270" y="77" width="100" height="80" />

      </bpmndi:BPMNShape>

    </bpmndi:BPMNPlane>

  </bpmndi:BPMNDiagram>

</bpmn:definitions>

Step 4: launch the main process

Log in to camunda platform through demo user http://localhost:8080/camunda/app/tasklist/default/#/login , initiate the main process:

Fill in process variables a1 and a2:

After starting the process, the process is in the first activity node of the main process. Click Submit process to automatically activate the sub process.

View the process variables of the main process at this time:

Step 5: start the sub process

Click submit for the main process. When the process execution reaches the subprocess calling activity, a new process instance will be created to execute the subprocess. At this time, the main process instance will wait until the subprocess is completely completed, and then continue the original process. Log in through user1 to view the sub process to-do and submit to-do tasks.

View the process variables of the sub process and find that the main process variables a1 and a2 are passed respectively and automatically mapped to b1 and b2.

user1 logs in to the system, views the sub process to-do tasks, submits tasks, the sub process ends, and the process automatically returns to the main process.

At this time, when viewing the main process variables, it is found that the sub process variable c1 is successfully returned to the main process and automatically mapped to the name c2.

The above demonstrates how camunda configures subprocesses, initiates subprocesses, and transfers variables between main subprocesses. Please refer to the official documents for details.

reference resources:

Call Activity | docs.camunda.org

http://www.yunchengxc.com

Keywords: Activiti Flowable bpmn camunda

Added by Rangana on Wed, 19 Jan 2022 06:34:04 +0200