Aggregating back data from multi-instance call activity

What is the recommended way of aggregating back data from multi-instance call activity?

In our particular case, objects are passed to the call activity through the collection & element variable. After completion of mult-instance, we would like to store data in the output collection?
What is the recommend way?

If you make the multi-instance a sequential, then you can write your data back to the parent process instance using something like ~execution.getParentExecution().setVariable… (or you could use the Variables Mapping and Output mappings on the multi-instance. Call Activity is a little more complex as there are extra scopes (Parent Process > Call Activity Local Scope > Called Process Scope). When you do the set variable you can continually update a existing variable such as a Json Array (using Camunda’s SPIN lib)

If you are using parallel multi-instance, then you have to deal with parallel writes to the parent process and will hit DB locking issues: The ~best solution I have found is to create a execution listener on the sequence flow (arrow) that comes out of the call activity, set the call activity to async-after (so the transaction is completed before the execution listener is called), and then in the execution listener to write a script/delegate that does something like the following:

  1. Get the Call Activity “Activity Id” that is attached to the sequence flow
  2. Look up the Call Activity “Activity Instance ID” for that “Activity ID” in that process instance
  3. use the ~“getCalledProcessInstance()” which will give you the Process Instance ID that was created using the Call Activity
  4. Then do a historic variables instance query on the process instance id
  5. You will need to filter out local variables which can be done with checking if ProcessInstanceId == ActivityInstanceId (if they are equal then it is a process instance variable) (

This will return you a list of Historic Variable Instances, and then you can parse those results as needed.

1 Like