Hi Tijs,
Thanks for your response. As per the suggestion, I have followed below logic but still could not come back to previous user task.
I was able to change execution activity using below code, but only 'ACT_RUn_EXECUTION' is updated with the activity details, corresponding changes to ACT_RU_TASK table did not happen.
List<Execution> executionList = runtimeService.createExecutionQuery().executionId("id").list();
List<HistoricTaskInstance> historyTaskList = historyService.createHistoricTaskInstanceQuery().processInstanceId("id").orderByTaskCreateTime().desc().list();
– get execution entity for a particular process instance
ExecutionEntity executionEntity = (ExecutionEntity) executionList.get(0);
– get process definition
ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) repositoryService.getProcessDefinition("definitionId");
– fetch activity details of the previous user task
ActivityImpl activity = processDefinition.findActivity(historyTaskList.get(1).getTaskDefinitionKey());
– set activity to execution
executionEntity.setActivity(activity);
– this method saves executionEntity
updateExecution(executionEntity);
– updateExecution command is as below. This will update the execution details with previous user task.
private void updateExecution(ExecutionEntity execution) {
final class UpdateExecutionCommand implements Command<ExecutionEntity>{
ExecutionEntity execution;
public UpdateExecutionCommand(ExecutionEntity execution){
this.execution = execution;
}
public ExecutionEntity execute(CommandContext commandContext) {
DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
dbSqlSession.getSqlSession().update(UPDATE_EXECUTION, execution);
return execution;
}
}
processEngineConfiguration.getJobExecutor().getCommandExecutor().execute(
new UpdateExecutionCommand(execution));
}
Since the ACT_RU_TASK table was not updated, I tried creating another command similar to above to delete current task details from run time table and create a new one for the previous step, but could not succeed with Delete command as it said, cannot delete a task from runtime table.
Could you please help me in understanding how to rollback to previous step so that execution starts from previous step again?