Based on your description, you’re experiencing the expected behavior of Camunda’s variable scoping system, but there are ways to achieve true local variables in parallel subprocesses.
The Issue
By default in Camunda, variables are created in the root (global) scope and are visible everywhere in the process instance. When your FEEL script task sets a variable, it’s being merged into the global process scope, which is why:
The variable appears global across the whole process
All parallel subprocess instances share the same value (the last one to execute overwrites the others)
Solutions
Here are several approaches to achieve true local variables in your parallel subprocesses:
1. Use Output Mappings to Control Variable Scope
Add output mappings to your subprocess or script task to control which variables get propagated:
If you define output mappings, only the mapped variables are merged globally
Variables not included in output mappings remain local to that scope
If you want to keep a variable completely local, simply don’t include it in any output mapping
2. Use Input/Output Mappings for Multi-Instance
If you’re using multi-instance subprocesses:
Use input mappings to create per-instance local variables
Use output mappings to control what gets merged back
Consider using outputElement/outputCollection to safely collect results from each instance
3. Variable Naming Strategy
Use unique variable names per subprocess instance to avoid conflicts:
// Instead of setting "item_plural"
// Set something like "item_plural_" + instanceId
Recommended Approach
For your specific case with parallel subprocesses, I recommend:
Add output mappings to your subprocess that only map the variables you actually want to be global
Keep working variables (like item_plural) local by not including them in output mappings
If you need the values later, collect them using a different approach (like an output collection)
Would you like me to help you implement any of these solutions? Could you also share:
Are you using multi-instance subprocesses or just parallel gateways?
What Camunda version are you using?
Do you need these variables to be accessible outside the subprocess later?
This is related to the concept of variable propagation.
To address this, you need to define the variable item_plural within the scope of each instance of the multi-instance embedded sub-process. This can be achieved using input mappings as shown in the attached snippet.
Yes, i can set an Input “local variable” for each subprocess.
But there, i set the variable inside the subprocess
And i can not set a “output local variable” in the script task
When you set a variable in a script task, variable propagation rules apply: if a variable with the same name already exists in the narrower scope, it will be updated there. If it doesn’t exist (like in your case), the variable gets created in the root/global scope.
In your scenario, you need the variable to be set within the scope of each instance of the multi-instance sub-process. This can be achieved using input mappings, which ensures a separate variable is created for each instance, holding the correct value set by the script task specific to that instance
Great! I’m glad the output mappings solution worked for you!
You’re absolutely right that it’s not very intuitive - Camunda’s variable scoping behavior can be surprising at first. The key takeaway is:
By default, variables created in script tasks become global, but you can use empty output mappings to keep them local to their scope.
This pattern is useful whenever you need working variables that shouldn’t interfere between parallel executions. Thanks for the feedback about the intuitiveness - it’s definitely one of those Camunda quirks that takes some getting used to!
Feel free to reach out if you run into any other variable scoping challenges.