Map tasks from subprocess to the main process

We have a Camunda engine at the backend of our system and the interaction is built on REST API. In our system we have a requirement to look for open tasks in Camunda for every object currently seen by the user on the screen where the user is a current owner.

In our system we store the processInstanceId got after starting the process to link our objects with processes. The processes themselves can call sub-process via call activity.

To collect all open tasks we use REST call to GET /task with assignee orcandidateGroups conditions. Using processInstanceId value from the response we map the task back to our object.

The issue is that the tasks from subprocesses return their own processInstanceIds which cannot be mapped back to our object.

We have found that we can request a parent process having subprocess processInstanceId using REST call to GET /process-instance with subProcessInstance parameter set to child processInstaceId. But here we can pass only single value for subProcessInstance parameter (accoring to documentation)

Are their any ideas how we can receive all the open tasks and map them to the main process instance with minimal number of REST calls?

Hi @alexeib,

Yes, this is possible bu using a bussinessKey. You would just need to revert your link logic. Instead of storing the processInstanceIds in the objects, you should instantiate processes with the object’s ID as the business key. The business key can then be passed on to sub-processes (embedded or as call activities), and can be used for filtering.

Here’s the Rest API endpoint for getting a list of tasks: https://docs.camunda.org/manual/7.10/reference/rest/task/post-query/. Properties 2 to 5 from the top describe filters for business keys.

Here’s a nice explanation from the Camunda blog on what business keys are and how to use them:
https://blog.camunda.com/post/2018/10/business-key/

Hope this helps,
Nikola

Thanks for response, @nikola.koevski. We had this scenario in our mind as well and all the main processes have unique business key. The issue is that when we request Rest API GET /task (or it could be POST) the result list does not have businessKey values and the tasks cannot be mapped to our object.

We have chosen processInstanceId value as it is part of result list and we can map task with object. It works fine for the main process, but it does not work if the task is from subprocess. With business key we can’t do any mapping at all (only filtering).

@alexeib, you are right. The business key can’t offer fine grained mapping when used with User Tasks and multiple business keys. You have to do a separate Rest call for each object in order to obtain all of its User tasks.

With External Tasks this is solved by storing and providing the business key together with the External Task.

However this is not the case for User Tasks. There, the filtering by business key is done by getting that information from the Process Instance and obtaining the correct tasks. The business key values are not forwarded to the task objects.

Maybe the business key can be easily added to a Task, since the Process Instance of a task is referenced in the TaskEntity. This would solve your problem, since you would be able to do a single Rest call and then map the tasks by business key.

If you like, you can open a feature request on Jira and reference this forum topic. There, we can discuss how we can make these changes. You can also make the whole process faster by implementing the changes yourself and submitting a pull request on our github repo.

Best,
Nikola