Impossible to pass variables to process during newThrowErrorCommand

Hello guys,
I’m developing a Job Worker in Spring Boot 3.0.5 using spring-boot-starter-camunda:8.2.4.
I’m also using Camunda Cloud on SaaS.

My worker should execute some logic and, in some cases, throws an error and to add a variable to the process.
For this purpose I’m using this code:

@JobWorker(type = "service-task-test-2", autoComplete = false)
public void handleServiceTestTask(final JobClient client, final ActivatedJob job) {
        
    // SOME LOGIC HERE....
        
    Map<String, Object> variablesMap = job.getVariablesAsMap();
    variablesMap.put("new_var", 999);
        
    client.newThrowErrorCommand(job.getKey())
                .errorCode("Error_99")
                .variables(variablesMap)
                .send()
                .join();
}

And this is a subset of my process:
image

I expect that the variables map of Service Task 3 should contains the new variable new_var, but it doesn’t.
It seem that .variables(variablesMap) is ignored.

What’s wrong with my approach?
Can you help me?

Regards,

Hi @Nassiesse - when returning variables with an error, those variables are local variables to the task itself, and therefore not automatically propagated to the process level. I believe you need to use the input/output mappings to propagate the variable. (Relevant docs link.)

1 Like

Thank you @nathan.loding for yout tip.
I’m pretty sure that you are right, I missed this part of documentation.

Anyway, in my opinion this design is not intuitive. If I throw an error and in the same action I also add variables, my expectation is to find them in the next step, otherwise why should I add that variables when throwing exception?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.