Multi instance result mapping

I have a multi-instance business rule task. As input I use a JSON array and thus iterate over the array entries.

The result gets mapped to a single output variable no problem, however as per the docs, the one process variable is overwritten. Hence Id like to copy the output variable value to a property of the current the relevant JSON array entry.

I tried an execution listener on the end event (assumes its called each iteration). Thus the execution listener has an expression ${var.prop(“outcome”,result)}. I get a cannot coerce java.lang.Integer to java.util.List exception.

Hence any tips on how to write a multi-instance decision output back into an entry in a JSON array?



Ok using an execution listener I can put the result of each iteration into a Jason property. However, it seems that using Jason spin array in a multi instance, the instance variable looks like it’s pass by value not reference. Hence whilst I can update it, it’s not really updating the original Jason array entry.
Is there a trick to spin pass by reference? Alternately, how can I replace the array entry in the original with the updated copy?

Hi Rob,

Reducing data when a multi-instance completes is a topic we haven’t got a clear answer to. There is no “pass by reference” option for process variables. In order to replace an element in the original array (assuming it is a SpinJsonNode), you can call spinJsonNode.removeAt(loopCounter) and then spinJsonNode.insertAt(loopCounter, newValue). There is no single replacement operation at the moment. I created a feature ticket, see CAM-5735.

Note that this effectively synchronizes all the individual instances of the mi construct via the array variable, so you might want to separate updating the variable from the rest of the inner multi-instance activities with an asynchronous continuation.

More “pass by reference”-like could be using the index to access the array elements, i.e. instead of specifying a loop collection, you could configure the number of instances as the size of the array and then use the loopCounter variable as the reference into the array to modify the array elements in place. Again, that may suffer from synchronization issues.


Thanks Thorben,

Yes I had a look at SpinJsonNode implementation and came to the same conclusion that there was no convenience method to update in place.

There also seems to be three scopes with some interesting behaviour when it comes to multi instance. Its as if there is process instance scope, multi instance scope and multi instance ‘loop’ scope. Its as if process instance scope variables are copied to multi-instance scope. Hence if I update a process instance scope variable in the multi instance task, it doesn’t seem to update the highest level scope item.

As a work around, if I call execution.setVariable(…) and thus create a new process instance variable, all works fine.