Handling subprocesses with REST API

Hi there,

I’m making a little grade project and decided to make good use of Camunda as bpmn tool. So far it works great, but I encountered a situation that goes as follows:

I have a process that calls another process (as an activity, by a bpmn file), and that one calls another activity process (also another bpmn file).
So far there are 3 levels.

I want to get the current task id from the third level (or the nth level if exists…), but I only have the first process instance id (the one that started all the flow).

So the question is how to get that task id (to complete) by calling the Rest API without making too much recursive calls, is there a nice way to do it?

I currently calling /process-instance?superProcessInstance=myProcessId to get the child subprocesses and the repeat that until I get to the desired level and get the task by name or the like

I think it’s not the correct approach, so that’s why I’m here asking :wink:

Any help is appreciated.

1 Like

Hi @migerusantte,

A common approach is assigning those process instances the same business key and then querying for tasks by that business key.

Cheers,
Thorben

HI @thorben,

Thanks for the quick response.
Can you tell me where to assign that business key? It’s a value that only lives with the current processes instances or a fixed one?

Ok, I found how to do it! :slight_smile:

I checked in Camunda Modeler the option “Business key” in each Call Activity and it works fine, I can get the related tasks, complete them and everything else.

But now I have a called Activity that calls another Activity, and that last one (when the child process starts) got “null” as the business key (I can see this null at Camunda Cockpit).

Multilevel business key pass is allowed?
Any idea about this? :frowning:

You can provide the business key during the start of the process.
For example via Rest API:

POST /process-definition/{id}/start
{
 "businessKey" : "myBusinessKey"
}

Could you try it and share if the children has it.
The business key should be propagated.

@Yana

Yeah, that’s what I do.

At the start of the first parent process I pass the businessKey the way you provided.

When it reaches the first Call Activity it pass correctly, but inside that Activity, it’s called another child Call Activity.
Happens that that called activity gets a “null” as the businessKey value.

Hi Miguel,

Sorry, I forgot a detail.
You need to pass the business key (via camunda:in) in the Call Activity:

    <bpmn:callActivity id="Task_0ir39hv" name="call B" calledElement="TestB">
      <bpmn:extensionElements>
        <camunda:in businessKey="#{execution.processBusinessKey}" />
      </bpmn:extensionElements>
      ...
    </bpmn:callActivity>

You need to adjust all of your Call activity elements like this.
Hope that helps.

@Yana,

Yep, I already did that, I have that camunda:in set in the first process Call Activity and in the child Call Activity of that one.

But still got null for businessKey :frowning:

In this case can you share an example of your processes so I can check them out.

Ok, I’m attaching the 3 files.

I just changed the names in the tasks and process to make it more readable.

Maybe it should have some errors by the changes, but just ask me if you encounter some.

First process calls “Element_A” (Second process) and that one calls “Sub_A” (Third process).

Thanks in advance.

ThirdProcess.bpmn (17.2 KB)
FirstProcess.bpmn (19.7 KB)
SecondProcess.bpmn (39.1 KB)

Hi Miguel,

I tried and it worked for me.
Have a look at “SecondProcess.bpmn”, maybe the problem is that SubB, SubC and SubD are not call activities but sub processes?

Best regards,
Yana

1 Like

@Yana

Thanks, I finally got it working by adding a process variable as my businessKey, in this situation that was the only thing that worked for me.