Writing a proper BACK button

Good day. Community,

My Camunda 7 ventures brought me to such a topic - BACK button.

I have a simple test flow:

The script tasks basically do the following:
image

First one sets the value of the variable test to 1, while the next one to 2. They are separated by user tasks, making it separate transactions.

I see the appropriate entries in act_hi_detail and can access them through historyService.

And here is where things get interesting.

I want to go back from User task B (should have marked them in the screenshot), to A (the first one). For this I am doing

untimeService.createProcessInstanceModification(processInstanceId)
		              .cancelActivityInstance(childActivityID)
		              .startTransition(idOfLastSuccessfulStep)

pointing from B to A, which is the last one succeeded.

But that doesn’t solve the problem of reverting the changes, made to the variables (and I need to remode changes done only by the last transaction).

And here is where I need help. I do assume that I need operation_id, but I’m currently thinking how to do it properly.

Thanks in advance.