Hello there,
i am trying to set a local variable in the scope of a subprocess(“multipl jobs”) but don’t know how to accomplish that.
To provide details on this question i have built a simple BPMN model and a test-service that completes a service task as an external task:
@Named
public class TestTaskHandler implements ExternalTaskHandler {
@Override
public void execute(ExternalTask externalTask, ExternalTaskService externalTaskService) {
try {
final Map<String, Object> localVariables = new HashMap<>();
localVariables.put("MY_DEPENDENT_JOB_ID", "some_id");
externalTaskService.complete(externalTask, null, localVariables);
} catch (Exception e) {
externalTaskService.handleFailure(externalTask, "failed...",
"failed...", retries, 60000);
}
}
}
In this case the process starts with a collection so that the subprocess starts 3 “subinstances” with the following json:
{“variables”: {
“A_COLLECTION”: {“value”:[1,2,3]}
}}
The external task is then processing those instances of the subprocess and should set local variables in the scope of “multiple jobs” so that the next service task is able to read this variable for this explicit execution and not globally.
Till now i have tested the following possibilities:
- complete the external task and set the variable as a normal variable. The result is that the variable exists globally (as expected)
- complete the external task and set the variable as a local variable. The result is that the variable exists only in the scope of the external task so that the following task is not able to read this variable
- the next try was to set an output on the diagram but the result of reading the local variable of the external task and setting this as the output leads to setting a variable globally again
- then i tried to set a local variable at the execution point by getting the execution id of the external task and calling the rest-api. This also results in setting the variable in the scope of the external task and not being accessible for the following task
At this point i am totally confused how it is possible to set the variable locally for the subprocess as described and i hope someone is able to answer this question.
EDIT:
The first design of the BPMN model had a service task where i was able to complete the task with a local variable in the scope of “multiple jobs” as i wished (by just calling “execution.setVariableLocal([…])” in the JavaDelegate class). The problem was that this task was taking to much resources for the current machine so that we decided to process the task by another machine as an external task. That’s why i assume this feature of putting a local variable in the desired scope should be possible…
BPMN:
test.bpmn (5.7 KB)
Thanks!