How to realize countersignature based on camunda: process configuration and principle analysis of camunda countersignature


1, Background

The famous open source process engines in the market include osworkflow, jbpm, activiti, flowable and camunda. Because jbpm, activiti and flowable process engines appeared earlier and are widely used by domestic people, we don't know much about camunda process engine. In fact, camunda is better than jbpm, activiti and flowable in function, stability, performance and lightweight. Chinese people use business processes, "countersigning" is one of the most commonly used process operations, so how to realize the countersigning process based on camunda and what is the execution principle of the process engine behind countersigning? The author hopes to give reference to the students who are studying camunda through this article.

2, What is countersignature

Countersignature: in process business management, tasks are usually handled by one person, while multiple people handle one task at the same time. This kind of task is called countersignature task.

1. In the order of countersigning:

a) Serial countersignature: serial countersignature is also called sequential countersignature. It refers to that user1, user2 and user3 receive to-do tasks in order according to the order of submitting process processors, and process the process in order.

b) Parallel countersignature: refers to that user1, user2 and user3 simultaneously receive process to-do tasks and process them in parallel.

2. According to the proportion of countersignature:

a) Pass all: all countersigners pass the examination and approval. After voting, they will pass the countersignature.

b) Pass by quantity: when a certain number of votes are passed, they will be countersigned.

c) Pass in proportion: if a certain proportion is passed, it will be countersigned after voting.

d) One vote: if one vote is passed, it will be countersigned.

e) One vote veto: as long as there is one negative vote, it will be countersigned.

The following describes how to realize countersignature based on camunda process engine, and analyzes the operation principle of process engine in detail.

3, Installing camunda BPM

First, complete the deployment of camunda process engine and camunda process designer, and create three new users user1, user2 and user3 to prepare for the design of countersignature process. See "camunda process engine quick start - Hello World example" for details,

4, Design countersignature flow chart

1. Draw a flow chart and set up a countersignature node

Camunda implements countersigning based on multi instance tasks and sets the node to multi instance, which is mainly configured on the attributes of the UserTask node. Select a user task and select Multil instance in the following attributes. You can see that there are two kinds of icons, namely serial countersignature and parallel countersignature.


2. Countersignature parameter setting

Description of main parameter configuration:

  1. loop cardinality: cyclic cardinality. Optional. You can directly fill in an integer to indicate the number of countersigners.
  2. Collection: collection. Optional. The collection of countersignature, usually list or loop cardinality.
  3. Element variable: element variable. Required when selecting collection. It is the element that the collection traverses each time.
  4. Completion condition: completion condition. Optional. For example, if one person completes the countersignature, the other person's agency tasks will disappear.

Code snippet of countersign node after setting:

<bpmn:userTask id="Activity_1udxyrq" name="jointly sign" camunda:assignee="${assignee}">
      <bpmn:multiInstanceLoopCharacteristics camunda:collection="assigneeList" camunda:elementVariable="assignee" />

3. Configure process handler

It should be noted that the Assignee, Candidate Users and Candidate Groups on the right represent the person in charge / Candidate Users / Candidate Groups respectively.

The current approver can be obtained by using the Assignee and filling in the content of the Element Variable field in the previous step. Note that it is a dynamic variable in ${} format, that is, each person traversed in the countersigner Collection is assigned to this variable.


4. Configure process listening events

In order to better realize countersignature, it can be processed by combining the Listener function of the process node. The listening types include Java class, Expression, Delegate expression and script. For text simplicity, use script to configure the countersignature processor.

For details on how to use groovy script, please refer to the official camunda documentation:


After setting, the configuration fragment of executionListener is as follows:

        <camunda:executionListener event="start">
          <camunda:script scriptFormat="groovy">def userList = ['user1', 'user2', 'user3'];execution.setVariable("assigneeList", userList);</camunda:script>

5. Complete BPMN process document



Complete BPMN process model file:

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

<bpmn:definitions xmlns:bpmn="" xmlns:bpmndi="" xmlns:dc="" xmlns:camunda="" xmlns:di="" xmlns:modeler="" id="Definitions_1lsa7z1" targetNamespace="" exporter="Camunda Modeler" exporterVersion="4.8.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">

  <bpmn:process id="Process_1n6xfcx" name="Test verification process 1" isExecutable="true" camunda:versionTag="1.0">

    <bpmn:startEvent id="StartEvent_1">



    <bpmn:sequenceFlow id="Flow_153mh25" sourceRef="StartEvent_1" targetRef="Activity_18krv16" />

    <bpmn:sequenceFlow id="Flow_1258z36" sourceRef="Activity_18krv16" targetRef="Activity_1udxyrq" />

    <bpmn:sequenceFlow id="Flow_0248t03" sourceRef="Activity_1udxyrq" targetRef="Activity_0neq0ra" />

    <bpmn:endEvent id="Event_00b1j9n">



    <bpmn:sequenceFlow id="Flow_0ucs2b7" sourceRef="Activity_0neq0ra" targetRef="Event_00b1j9n" />

    <bpmn:userTask id="Activity_18krv16" name="apply">


        <camunda:executionListener event="start">

          <camunda:script scriptFormat="groovy">def userList = ['user1', 'user2', 'user3'];execution.setVariable("assigneeList", userList);</camunda:script>






    <bpmn:userTask id="Activity_1udxyrq" name="jointly sign" camunda:assignee="${assignee}">



      <bpmn:multiInstanceLoopCharacteristics camunda:collection="assigneeList" camunda:elementVariable="assignee" />


    <bpmn:userTask id="Activity_0neq0ra" name="Examine and approve" camunda:assignee="user2">





  <bpmndi:BPMNDiagram id="BPMNDiagram_1">

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

      <bpmndi:BPMNEdge id="Flow_0ucs2b7_di" bpmnElement="Flow_0ucs2b7">

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

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


      <bpmndi:BPMNEdge id="Flow_0248t03_di" bpmnElement="Flow_0248t03">

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

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


      <bpmndi:BPMNEdge id="Flow_1258z36_di" bpmnElement="Flow_1258z36">

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

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


      <bpmndi:BPMNEdge id="Flow_153mh25_di" bpmnElement="Flow_153mh25">

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

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


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

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


      <bpmndi:BPMNShape id="Event_00b1j9n_di" bpmnElement="Event_00b1j9n">

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


      <bpmndi:BPMNShape id="Activity_068boyx_di" bpmnElement="Activity_18krv16">

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


      <bpmndi:BPMNShape id="Activity_10kl1f8_di" bpmnElement="Activity_1udxyrq">

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


      <bpmndi:BPMNShape id="Activity_1duyn2a_di" bpmnElement="Activity_0neq0ra">

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






6. Release process

Fill in the name of the process model, set the Camunda REST service address, and publish the process.

7. Configure groovy parsing package

Set and configure groovy parsing package for camunda process engine. Find the camunda installation directory camunda-bpm-run-7.15.0\configuration\userlib and place a groovy-all-2.4.13 Jar, otherwise an error will be reported during the running process of the process engine, indicating that the groovy script cannot be parsed. Groovy package download address:


8. Turn on java serialization

Turn on java serialization for camunda process engine. For security reasons, camunda turns off java serialization by default. This example involves the storage and parsing of countersignature collection process variables. In fact, it is an ArrayList, so you need to turn on java serialization.

For details, please refer to camunda's official website:

After configuration, restart camunda process engine.


5, Analysis of countersignature process operation


1. Log in to camunda BPM

Default address:

Default password: demo / demo

2. Start process

Click the "Start process" button to pop up the process template selection box, and click the name of the process to start.

After the process is started, click Complete in the application node by default to submit to the next countersignature node.



3. Countersignature approval

(a) User1 logs in and sees that the process has been submitted to the countersignature node.

(b) View process variables through the interface


When in the countersignature node, the task will automatically generate the following process variables:

  1. Nrofactivateinstances: the number of instances of current activity, that is, the number of instances that have not been completed
  2. loopCounter: loop counter, the index of the handler in the list
  3. nrOfInstances: the total number of instances in countersignature
  4. nrOfCompletedInstances: the number of completed instances

Condition ${nrOfInstances == nrOfCompletedInstances} indicates that countersigning ends after all personnel have completed approval.

The condition ${nrOfCompletedInstances == 1} indicates that one person has completed the approval.

(c) Fill in the approval comments

Each countersigner can fill in process comments. Fill in the process comments first, and then submit the process, that is, complete the countersignature operation.


(d) View the database table

View act_ ru_ In the execution table, there are 3 active instances

View act_ru_task table. There are 3 to-do tasks at present

View act_ru_variable table. By viewing the current process variables, you can see that the total number of activity instances at this time is 3, the number of unfinished instances is 3, and the number of completed instances is 0.

(e) user1 submits the process, completes the countersignature and submits it to user2.


After the first countersignature, the values of process variables nrofactiveinstances, loopCounter, nrOfInstances and nrOfCompletedInstances have changed.

(f) View the database table

View act_ ru_ In the execution table, there are 2 currently active instances

View act_ ru_ In the task table, there are currently 2 to-do tasks, and the to-do of user1 has disappeared.

View act_ru_variable table. By viewing the current process variables, you can see that the total number of activity instances at this time is 3, the number of unfinished instances is 2, and the number of completed instances is 1.


(g) According to the above operation, user1, user2 and user3 all complete the countersignature, and the process flows to the next node.

(h) Query process variables through the interface, and all process variables related to countersignature control disappear.

(i) View database table records

View act_ ru_ The execution table and countersignature activity instances have all disappeared.

View act_ ru_ The task table and the countersigned to-do tasks have all disappeared.


View act_ru_variable table, check the current process variables, and all process variables related to countersignature status control disappear.

View act_hi_taskinst table, which records the history of to-do tasks. You can see three historical to-do tasks related to countersignature.

View act_hi_varinst table, which records the history of process variables.

View act_hi_comment table, which records the process approval opinions. You can see that the approval opinions of user1, user2 and user3 are recorded in this table.

6, Summary

The above is the countersignature function based on the open source version of camunda process engine, without any secondary development. The goal is to enable readers to quickly run and verify camunda process engine without writing code. In the actual business scenario, these are far from enough. Camunda needs secondary encapsulation and expansion, including integration with enterprise organization users, process handler configuration, process approval page beautification, and the realization of process functions with Chinese characteristics such as process return, revocation, retrieval, jump, signature, transfer and circulation. The domestic cloud process low code platform adopts camunda process engine and has a free test experience environment , you can experience it directly.











Keywords: Activiti Flowable camunda

Added by Scip on Fri, 28 Jan 2022 16:27:44 +0200