Aggregate and pass child processes camunda variable to parent process

Hi,
From Parent process I am triggering multiple child processes using callActivity.
Each child process sets a variable called “serviceKey” with a String value.

Now how can I get a variable in Parent process called “serviceKeyList” with List<String> as the value?

After callActivity parallel child processes are all done, using asyncAfter and End Execution Listener I can trigger an execution listener in the Parent process.

Is there any Java code example where I can iterate over all child processes variables in this execution listener and make a list of String? Also, is there a better approach within Camunda itself for such an aggregation (Out mapping propagation would not work because one child process would override another child process variable instead of aggregating).

Hi @firstpostcommenter, along the lines you are thinking of I’ve attached a possible solution for you to have a look at ….

ChildCallable.bpmn (2.5 KB)
ParentCallable.bpmn (4.2 KB)

Have the child process return it’s serviceKey as a local out mapping. This creates a local in the instance of the multi-instance parallel call task of the parent. Add an “end” execution listener to each instance of the parent multi-instance which reads the (global) serviceKeyList, appends the local serviceKey to it and finally updates the serviceKeyList variable.

For clarity in the process engine logs, I’ve also passed down the loopCounter to the child process so that it can do a simple sys.out log of that value. This helps a bit when comparing behaviour with/without “async before” and “exclusive” flags.

If you configure the parallel multi-instance with async before & exclusive == false you will get some contention (optimistic locking exception) on writes of the serviceKeyList variable but the engine will keep trying these until resolved (and they will resolve) …

Hope this helps!
(7.22 Community Edition)

1 Like

Hi, The use of the local out mapping variable in callActivity is useful for me in this situation. Thanks.

I did not understand the point about locking issue. When I enable asyncBefore then exclusive is also enabled by default by Camunda modeler and I keep it that way. So I assume that locking issue will not happen in this case?

Hey @firstpostcommenter - yes, you can leave “exclusive” on and you won’t get the OLE. On the other hand you won’t get parallel execution of the child process across the process engine job workers because:

An exclusive job cannot be performed at the same time as another exclusive job from the same process instance.

Yes, the end execution listener will be called per child process irrespective of async

1 Like

oh, I was not aware that parallel multi-instance will behave like a sequential multi-instance when exclusive flag is set to true. Should exclusive flag be set to false in both the “Called element” section and “Multi-instance” section of the callActivity for it to behave as parallel multi-instance?

good question and I always end up experimenting with the behaviour with the different configs and some sys outs to make sure I understand.

I think the important one is the async before + non-exclusive on the “Called element”.

This part of the transactions page is useful …

1 Like

I see that even with asyncBefore and Exclusive flag enabled, multiple child processes are being triggered from the Parent process. Might be because the all delegates and the child process are also having asynchronous continuation. So only the triggering of child process from callActivity might be happening sequentially but both child process are running in parallel.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.