cancel
Showing results for 
Search instead for 
Did you mean: 

Re-Try user task

prabhanjan
Champ in-the-making
Champ in-the-making
Dear Team,

We are using ACTIVITI 5.17.

We have a requirement from client which I am unable to map to Activiti features. Client wants that an admin user should be able to rollback any "User Task" to any of the previous stage at any point of time.

For example, following is my process, where "A", "B", "C" and "D" are user tasks

start –> A –> B –> C –> D –>end

Client want that at any point of time during a single process execution, an admin user should be able to rollback workflow execution from state "D" to any of "A" "B" or "C".

Is that possible in Activiti?

I have read another post mentioned below which had a similar requirement and the suggestion was to 'change execution activity' using 'managementService.executeCommand'.

http://forums.activiti.org/content/user-task-rollback

I have looked at all the commands that are available in ACTIVITI API and could not find a command to change execution activity.

1) Is this feature directly avaliable in ACTIVITI? If yes, could you please share the details?
2) Are we suppose to write this command?

If I try to delete the current active task to go back to previous user task using below command, I get an error saying the task is active and mapped to the execution.

managementService.executeCommand(new DeleteTaskCmd());

Thanks in advance for you help!
3 REPLIES 3

trademak
Star Contributor
Star Contributor
Hi,

It's an interesting feature and we will be looking into more dynamic behaviour for the next releases of Activiti.
Right now the best option would be to write a custom command and use the ManagementService executeCommand method to execute your custom command logic. In this logic you can lookup the execution for the current task and set the activityId to the new user task id.

Best regards,

prabhanjan
Champ in-the-making
Champ in-the-making
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?

sankaran_pv
Champ in-the-making
Champ in-the-making
Hi,

We are also looking for a similar solution. @prabhanjan did you get it working?

Thanks
Sankaran