Change Process Variable from the external task?


#1

Hi,

is it possible to change a process variable defined in the Camunda Modeler over the external Task ( in java). I tried the charge card worker example from https://docs.camunda.org/get-started/quick-start/service-task/#add-the-java-class. In this Java Class the value of the variable “amount” is retrieved from the process with this code:
Long amount = (Long) externalTask.getVariable(“amount”);
Could it be possible to update the valute of “amount” over the external task and to give the new value back to the running process?

thank you


#2

Hi @Elousha ,

yes you can set and update the process variables in an external task.

long amount = (long) externalTask.getVariable("amount);
long newAmount = amount + amount;
externalTaskService.complete(externalTask, Collections.singletonMap("amount", newAmount);

When you complete an external task you can pass a Map<K, V> to the complete-method with all the values you want to set to the process. Because it’s just one value in the example I chose to pass it really simple with a singletonMap, but you can also create your own Map in the code before and pass it at this point. If you don’t want to override your old amount-value you should choose a new name for the new process variable.

Hope that helps.

Regards
Michael


#3

Thank you Michael
This solve my Problem :slight_smile:

Regards
Elousha