I have a BPMN process with a sub-process within it. There are different flows leading to the sub-process. And I want to know, once inside the sub-process' execution, which flow has led to the current execution.
To this end I think variables could be handy. So I conducted a test in which I wrote a couple of scripts for flow's listener leading to the sup-process.
execution.setVariableLocal("V", "Expecting it to be local to the sub-process' execution");
But it turned out that execution
points to the outer/parent process and thus the variable was set in parent scope.
So is there anyway to set an execution local variable from outside?
The simplest approach (basically use getVariable
instead of getVariableLocal
):
take
event of the sequence flows of interestIn the execution listener, perform
execution.setVariableLocal("flowTaken", execution.getCurrentTransitionId());
Access it in the sub process via
execution.getVariable("flowTaken");
If it has to be a local variable in the sub process:
take
event of the sequence flows of interestIn the execution listener, perform
execution.setVariableLocal("flowTaken", execution.getCurrentTransitionId());
In the BPMN 2.0 XML, define a variable input mapping for the subprocess:
<subProcess ...>
<extensionElements>
<camunda:inputOutput>
<camunda:inputParameter name="flowTakenAsSubprocessLocalVariable">${flowTaken}</camunda:inputParameter>
</camunda:inputOutput>
</extensionElements>
...
</subProcess>