Output mapping writes to unexpected scope


I´m not sure if I do not understand output mapping and scoping the right way, or a bug has crossed my way.

I have two processes with parallel process paths, one with a parallel gateway and one with a multi-instance sub-process.

In both processes a variable called “variable” is initially set in the process instance scope and then changed in each parallel path. In the parallel paths it is changed via output mapping of a script task. After changing the variable, both parallel executions are stopped with a dummy receive task (only for displaying purposes).

What I would expect as “variable” value is:

  • Process instance execution: “base”
  • Execution 1: “1”
  • Execution 2: “2”

What I really get is:

  • Process instance execution: “2”
  • Execution 1: “2”
  • Execution 2: “2”

The technical reason for this is the implementation in class org.camunda.bpm.engine.impl.core.variable.mapping.OutputParameter. It calls setVariable on the outer scope. This means that the variable value is stored in the deepest scope, which has already a value for the variable. If not, the highest scope (the process instance itself) is used.
Without output mapping everything works fine.

If it is not a bug: Where is the mistake in my expectation? How can I change a variable locally with the help of output mapping?

I´ve added a test project to reproduce the situation

Thanks in advance!!


I would be grateful for any hint :thinking:

Hi Carsten,

This does indeed work as intended. If you would like to set the variable on a different scope, you can implement an execution listener and then use the #setVariableLocal APIs as needed. An alternative is to “declare” a variable in an execution (e.g. in a start listener) before a task is executed and then the output mapping will not propagate to the highest scope, but only to where the variable has been set before.


Hi Thorben,

thanks for your reply. Your answer confirms my doubt about myself having understood the output mapping the right way. But I still think that it is a little bit circuitous to achieve my goals. Maybe - for the future - it might be a good idea to allow some kind of configuration in the output mapping whether to propagate to local or global scope?

Best regards,