Setting a Subprocess Variable while in a Parallel Gateway


I have the following rather simple setup: I have an embedded subprocess which holds a parallel gateway leading to two user tasks. Afterwards the execution gets joined again.

When finishing one of the user tasks, I set a local variable, but the thing is, after the join of the two parallel flows, the variable is gone.

I would like to set the variable such that it is local to the subprocess, so it still is available after the join, but I don’t want to use global variables, which would be visible in the parent processs.

Is this possible?

Thank you & best regards,

Hello Raul,

In order to use/see variable, it has to be define in this scope. So after the join the variable is gone because it is out of scope. (You can check for more information here.)
I am not sure if it is applicable to pass the variable to another variable within the parent scope.
Why don’t you want to use global variables? What is your goal?

Best regards,

Hello Yana,

I forgot to mention it - it is a multi-instance subprocess. I would like to keep the variable local to its respective subprocess instance, so that I still have access to it after the join, but I don’t want it to spill outside the subprocess itself, otherwise I would have concurrency issues.

Add: I’m thinking about searching for the execution of the subprocess itself to set the varibale there, but in the execution query I’m missing something like processEngine.getRuntimeService().createExecutionQuery().processInstanceId(…).executionDefinitionKey(DEFINITION KEY OF THE EMBEDDED SUBPROCESS)

Thanks & cheers,

Hi @rfechete

Please see below post

Hi @hassang,

The thing is the subprocess instance is already running at that point, and it’s sitting in a section isolated by a parallel gateway. In your example, the variable is set by a Start Listener.


Hi @rfechete
In your case you can set the local variable to null on the start event of the subprocess. Then set it to the proper value later. The purpose of setting an empty variable on the start event is to create your variable in the right scope (that way you will have a local variable for each subprocess instance)


Hi @hassang,

That did it! Setting the variable in the start listener and then modifying it later as a global variable (when setting it as a local variable within the parallel gateway it still reverts to the original start listener value upon join) produces the intended effect.

Thank you!
Cheers, Raul

Hi @rfechete
Parallel Gateway will generate a new child execution “scope” for each outgoing path. That is why you shouldn’t use setVariableLocal from there as in your case it would create a new variable explicitly on the child scope where its called from. Using setVariable from there would set your already created variable which available in parent scope “subprocess instance”.