Go back to previous user task

This post helped me to achieve this. Process modification works perfectly.

What I did to achieve this is to store the transitionId of the previous userTask in the session, so when the user clicks on the back button, below code runs and it goes back to the previous user task.

You need to find the current activityInstanceId as well, and I assume you already know the process instance id.

String activityInstanceId = null;

ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstanceId);
if(activityInstance != null){
	if(activityInstance.getChildActivityInstances() != null){
		ActivityInstance childActivityInstance= activityInstance.getChildActivityInstances()[0];
		activityInstanceId = childActivityInstance.getId();
	}
};

runtimeService.createProcessInstanceModification(processInstanceId)
					.cancelActivityInstance(activityInstanceId)
					.startTransition(transitionId)
					.execute();
1 Like