Variables scope


I encountered a strange behaviour:

When I add variables to a task and complete the whole process, I can no longer see the variables on that task. Based on the DOCS this should not happen as long as the variables are not local.

The HistroyService shows me the variables when querying them from the process


but not when I query them from the task


To explain the problem a little more, I wrote a simple test case. I expect that all five test succeed. However the last three, where I try to get the variables from the tasks, fail.

I fixed it by using setVariableLocal. However in this case I don’t understand why the variables are visible in the process scope?

The logic is as you’ve described in your update:

  • by default, variables are set on the process instance level
  • if you set variables local (task/execution), they get a reference to that local task or execution. However, the variable is always enriched with the process instance id (if applicable, not for standalone tasks) for query purposes.

When a .getVariable() is done, the local scope is always checked first, before going upwards in scopes and eventually ending up at the process instance level.

Thanks for the explanation.