Completing task with local variables

I am working with Camunda engine via a rest API, there is a following question which I would like to answered with your help.

Let’s say I have two managers, who is supposed to approve requests. Hence, there are two user tasks with two gateways down the flow. Is it possible to use the same variable to control the execution path?
In the following discussion Redirecting to Google Groups

a workaround is offered, which is to set task local variables first and then complete the task
But what about the gateways, are these local variable accessible to gateway sequence flows to be evaluated? I guess no.

Do I have to create a unique variable names for each user task if I need to have gateways afterwards?

Hi @nomadus,

can you please share your BPMN process?

Best regards,
Philipp

Hi,
I actually resolved this by adding TaskListener on task complete event and setting process variable value with task local variable value.
I hope this is the correct approach.

public TaskListener getTaskListener() {
    return new TaskListener() {
        public void notify(DelegateTask delegateTask) {
            _Logger.info("A global task listener event " + delegateTask.getEventName() + " fired for " + delegateTask.getName());
            String taskOutcome = (String) delegateTask.getVariableLocal("taskOutcome");
            if (taskOutcome != null) {
                if (delegateTask.getEventName() != null) {
                    if (delegateTask.getEventName().equals("complete")) {
                        _Logger.info("Setting task outcome to  " + taskOutcome);
                        delegateTask.setVariable("outcome", taskOutcome);
                    } else {
                        delegateTask.setVariable("outcome", null);
                    }
                    delegateTask.setVariableLocal("taskOutcome", null);
                }
            }
        }
    };
}

Hi @nomadus,

I can’t say if this is the correct approach because I don’t know your BPMN process.

However, it seems that you set or update the process variable “outcome” when the task is completed. This looks good so far. If the listener is only called on ‘task completed’ when you don’t need to set the local variable to null.

Best regards,
Philipp

Hi @Philipp_Ossler,

I’m using external tasks and the REST API for complete has the localVariables parameter.
How does the parameter work?

The local variables set in the first service task do not show in the next service task.
This happens in the context of a process having two service tasks.
I noticed this, when I tried to use it in the context of a parallel multi-instance.