Process automation with Camunda using dotnet6: part 2

Satyam Pushkar
6 min readJan 19, 2022

This article explains how to create gateways, sub processes, manage human tasks, handle errors etc. in Camunda and BPMN. To know the basics please check out the first part of it here.

Photo by Campaign Creators on Unsplash

In last article, I have explained the basics of Camunda, BPMN, process automation and then showcase a very simple app about how to use Camunda with dotnet6 for process automation. This article is trying to explain few more important basic blocks to create a featureful and robust process.

Gateways: Create Control Flow Processes

While creating or defining a process, we need to introduce modelling decisions based on data and events. For this BPMN2.0 has different types of gateways: Conditional and Default Sequence Flows, Inclusive Gateway, Parallel Gateway, Event-based Gateway and Data-based Exclusive Gateway (XOR). You can find more detailed information here. To demonstrate the capability, in this article I have created an example about Data-based Exclusive Gateway (XOR). It is also called exclusive data-based gateway.

When the execution arrives at this gateway, all outgoing sequence flows are evaluated in the order in which they have been defined. The very first sequence flow which condition evaluates to ‘true’ is selected for continuing the process. Please check the process flow defined below which shows that how based on a condition process flow happens. You can find the BPMN diagram here. There is a service task which checks the availability of items and based on that sets a process variable itemsAvailable to true/false accordingly. You can find the sample code in CheckItemsAvailabilityHandler.

In the process there is a gateway included (showing with X mark). From that two sequences(lines) are forked; one showing ‘yes’ and another showing ‘no’. If you click on any of the sequence, you can see on the right pane: there is a ‘Condition Type’ and an ‘Expression’ textbox. Condition is defined as ‘${itemsAvailable==true}’ for sequence ‘yes’. Whichever sequence evaluates to ‘true’, the process flow goes in that direction.

exclusive data-based gateway

Subprocess: Make Reusable Processes

While writing a software program, we create a function to reuse the functionality. On the same line, using BPMN2.0 standards we can can create a subprocess which can be reused in different processes. There are four different subprocesses available: Embedded Subprocess, Call Activity, Event Subprocess, Transaction Subprocess. You can find more detailed information here. For this article I have created an example about Call Activity.

Call Activity references a process that is external to the current process definition. For example, we need to check the availability of items in the process of preparing tea. Hence I have created a process called ‘Check Items Availability.bpmn’ which is then referenced in the process ‘Prepare Tea.bpmn’. Please check the image below.

You can see here that there is a call activity(with a thicker outline and a plus sign within) is added in ‘Prepare Tea.bpmn’. If you click on it, on the right pane you can find the configurations. Here CallActivity Type is selected as ‘BPMN’ and Called Element is referring to the process ‘Process_Check_Items_Availability’. This way the sequence flow goes to the called subprocess and once returned will proceed in current process.

Error Events: Catch & Throw Errors in Processes

Events describe something that happens during the course of a process. For different events, different types of throw/catch events are available. BPMN supports different types of events: Start Events, None Events, Message Events, Timer Events, Error Events, Escalation Events, Signal Events, Cancel and Compensation Events, Conditional Events, Link Events, Terminate Events.

Start and Terminate events are very common and you must have see in all the BPMN diagram shown till now in this article. Timer and Conditional events are very useful in defining processes with different use cases. To get more details about events please check here. In this article I am capturing the Error Events as I feel it’s very important to make processes errorproof by basically handling it properly. Please check the image below where I have shown one example about how errors can be thrown and captured in BPMN2.0. The error thrown from subprocess is captured in the calling process.

Error event

User Task: Involve Human Participation in Processes

Tasks allow modeling the actual work being performed in the process. In all the process shown in this article and the previous one, I have used only the Service Task. But BPMN2.0 provides different types of Tasks: Service Task, Send Task, User Task, Business Rule Task, Script Task, Receive Task, Manual Task, Task Markers. You can find more detailed information here. For this article I have created an example about User Task.

User task is a way we can add human participation in business processes. For example in our Prepare Tea process, when the items are unavailable we inform inventory about it and then some actual person will refill the inventory. Once he or she refills it, they can mark the task complete and then only the process continues to perform further task(s). Please check the image below which shows human task.

human task example

The ‘Refill Inventory’ is a user task. To mark any task as a User Task, click on the task and then click on wrench button. This will show all the options of Tasks; you can choose a ‘User Task’ if intended.

Once the flow comes to this task in process, any user has to intervene and mark this task complete. This can be done from Camunda portal(Human Task tab).

This can also be done through rest call. This gives flexibility to integrate these human tasks in our own web portal/apps/systems. Please check the code in below image. You can check the CamundaProcessController to get the code implementation.

Note:

  • The repo has BPMN diagram specific to each of the use case shown above. While deploying please always go to deployments and delete the old deployment from Camunda webapp(deployments tab).
  • If you want to use one diagram with all the features you can use the one explained in last case: ‘Prepare Tea with Manual Task.bpmn’.

This was a sample use case showing how to start working with Camunda. Hope this article has helped you understand the basics of Camunda. To know further about Camunda please check the first part here.

For further reading you can check out Camunda docs or this link.

Please do checkout other articles by me and share your feedback(s) if any. Thank you.

--

--

Satyam Pushkar

Software Engineer | Backend Specialist | System Architect | Cloud Native Apps | DOTNET, PYTHON | https://www.linkedin.com/in/satyampushkar/