Settings variables in multi-instance branch scope

Hi, I have Operaton set up as a standalone application (using the Docker images) where Java applications execute tasks using the Java library org.operaton.bpm:operaton-external-task-client@2.0.0.

I am trying to introduce multi-instances (expanded sub processes) into the BPMN model, but have been unable to create variables in the multi-instance scope from the external tasks. How would I go about this? Ideally, the solution doesn’t require the external task implementation to know whether it is in multi-instance scope or not (because that seems to be a detail of the model, not the task)

I’ve been using a minimal BPMN model (see below). The script task creates a list of numbers (execution.setVariable("list", S("[1, 2, 3]"));). The multi-instance loops over this collection with element variable number. The first external task creates a copy of number called copy with the handler

(externalTask, externalTaskService) -> {
    Map<String, Object> variables = externalTask.getAllVariables();
    variables.put("copy", variables.get("number"));
    externalTaskService.complete(externalTask, variables);
}

I’ve tried different versions of this, such as passing the copy variable in a localVariables map or by settings outputs in the BPMN model, but all result in a single copy variable on process instance level instead of a variable per multi-instance branch:

Any suggestions?

Hi @beekum, thanks for reaching out!

I have some time on my hands to look into this, but it would be easier for me if you could share your BPMN model here as an attachment, so I’m sure that I’m comparing the same things, would that be possible?

I hope I understood your usecase correctly, I hope this helps (not sure, as you already mentioned localVariables):

        client.subscribe("create-copy-of-numbers")
                .lockDuration(20_000)
                .handler((externalTask, externalTaskService) -> {
                    Object number = externalTask.getVariable("number");
                    Map<String, Object> localVariables = new HashMap<>();
                    localVariables.put("copy", number);
                    externalTaskService.complete(externalTask, null, localVariables);
                })
                .open();

externalTaskService.complete can be overloaded, the third parameter contains variables which should explicitly be written to the local scope.

If I run this external Task Service, I can see the following in the Cockpit:

The Scope for the variable “number” is “For Each Number”, the variable exists once per parallel execution