Go back to previous user task

I have a use case where I need to use a “Back” button to go back to previous user task programmatically.

Assume that same user runs a single process and completes user tasks from start to end.

START => UserTask-A => UserTask-B => UserTask-C => END

At any point in the flow, user can click on a “Back” button and the process should go back to previous UserTask.

I can not use extra transitions in the model builder to go back, because I have giant flows and this needs to be done programmatically via spring service beans like TaskService, RuntimeService, etc.

Is this possible ? Or any suggestions to implement this functionality ?

Can you upload your model or enough of the model so that we can visualize what you’re trying to do.

Also is it a service that decides to “go back” or a user?
What is the reason for going back? an error? undoing something?

The reason for going back depends on user choice. See below sample model (which is a very basic one to explain the need).

If user completes the first task with “taskNotValid” option and realizes this was not correct, he/she needs to go back to choose the option “taskValid”. I need an api call to do that, I can store the previous task data in my backend.

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