Getting local variables of a sequential multi-instance


I am using a sequential multi-instance service task such as this using a Java delegate

For a parallel multi-instance, each iteration has a unique execution id, but it looks like all iterations of a sequential multi-instance have the same execution id. I would like to know how I can get the local variables used for each iteration of the sequential multi-instance.


Hi @cambarantama,

What do you mean by local variables? Do you mean item variable?
And from which point you are trying to access local variables?

1 Like

If it’s the same execution: Doesn’t it mean that the local variables are shared between all the iterations?

Yes, I mean the item variable? I would like to see in history view different values item had.

1 Like

Hello my friend @cambarantama !

In camunda, when entering a multi-instance, some variables are created, and one of them is loopCounter which is of type “Integer”.

You can use this variable to concatenate with the name of a variable you want and thus have direct access to the variable referring to the multi-instance you want.

For example, if your variable is “personName”, and your multi-instance will have 30 persons, you create the variable dynamically by searching for the value of the current running loopCounter through execution.getvariable(“loopCounter”)… and then concatenating the loopCounter value with the name of the variable.

“personName_” + loopCounter;

Something like this!

Hope this helps.

William Robert Alves


Hi @WilliamR.Alves !

Thanks for the suggestion. This this helps too.

I am looking for a REST call that I can use without having to create new variables. For example, this POST /history/variable-instance with query parameters

	"processInstanceId": "ac662404-9937-11ee-af90-005056027c2e",
	"variableName": "item"

then see different values item has had in the multi-instance.


Hi @cambarantama,

I believe that /history/variable-instance endpoint should return the variable instances of the named variable item. Keep in mind that activities are created sequentially and so on element variables.

Doesn’t it work for you?

Did you set the history setting to “full”? Only then all the values a variable takes on are recorded.

1 Like

Surprisingly, I am getting one variable instance from a multi-instance which run 3 times
test-process.bpmn (3.0 KB)

Hi @cambarantama,

It looks like you are calling the API while only first instance has been created and it hasn’t been completed yet so the remaining instances including their item variable are not created yet because multi-instance activity is configured to run sequentially.

Hi @hassang,

I am calling the API after all instances are completed. You can see the history view here

Hi @cambarantama,

Yes, you’re correct.
I conducted a small test and found that
In sequential multi-instance situations, the same activity instance is used one after another, so only one value is kept.

One solution to overcome this is to remodel it as follows

Attached is a simple working example with a JSON collection
test_multi_process.bpmn (6.0 KB)


Thanks for the suggestion!

1 Like

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