Get process variables in IncidentHandler

Hi,
I’ve got a very simple workflow, with few Service Tasks, no branches, just one task after the other till the end.
Additionally I implemented a custom IncidentHandler to catch and process any thrown exception.

So I start a process passing an input variable with value “VALUE_1

String processInstanceId = processEngine.getRuntimeService()
                .startProcessInstanceByKey(PROCESS_NAME, Variables.putValue("var_name", "VALUE_1"))
                .getProcessInstanceId();

Then in a Service Task I update that variable to VALUE_2:
execution.setVariable("var_name", "VALUE_2");

If an exception is raised from any of the following Service Tasks, the IncidentHandler kicks in and I need to fetch the modified variable, which I do like this:

var my_var = (String) executionEntity.getVariable("var_name");

The point is that if in the IncidentHandler I print out that value I get VALUE_1, so it looks like the update in the Service Task didn’t stick.

What am I doing wrong?
Thanks.

Hi @ciccio,

Nothing. In case of an exception, a rollback is done.

You can read more about this in this blog post: https://camunda.com/blog/2022/02/achieving-consistency-without-transaction-managers/ , especailly in the section ‘Anecdotes from Jakarta EE’.

Hope this helps, Ingo

1 Like

Thanks, I thought the only possible rollback was possible through compensation.
Adding some Asynchronous Continuation fixed my issue.