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 Executing automated steps (2/6) | docs.camunda.org. 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?
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.
Thanks, your explanation helps me, too.
But there is another question: Why isn’t this possible with externalTaskService.handleFailure(...) (there is no equivalent method parameter)?
Background information regarding my question: My ExternalTask executes two steps, the second one requires a result from the first one. If one of both steps fail, I’m using handleFailure method with retries and retryTimeout set, which makes Camunda invocing my Task again later on if timeout is over. At this point I want to set the result from the first step (if successful) to skip this step when retry invocation occurs.
this sounds like a too obvious kind of solution
It would be nice to have both steps together in one type/business step, cause they are closely related from a business point of view.
I’m going to take your recommendation to our team meeting, thanks.