How can the flowable framework implement the process rollback functionality?

Flowable is a process engine that offers built-in features for implementing process rollback.

To achieve the function of process rollback, you can follow these steps:

  1. Historical Service
  2. generate a query for historical task instances
List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery()
    .processInstanceId(processInstanceId)
    .orderByTaskCreateTime()
    .desc()
    .list();
  1. Identify the target task to roll back to: Locate the target task in the list of historical tasks based on the index of the task that needs to be rolled back.
HistoricTaskInstance targetTask = historicTasks.get(targetTaskIndex);
  1. Service that manages the runtime of an application
  2. generate a query for process instances
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
    .processInstanceId(processInstanceId)
    .singleResult();

ProcessInstance targetProcessInstance = runtimeService.createProcessInstanceBuilder()
    .processDefinitionKey(processInstance.getProcessDefinitionKey())
    .variables(processInstance.getProcessVariables())
    .start();
  1. Service of tasks
  2. finish
Task targetTask = taskService.createTaskQuery()
    .processInstanceId(targetProcessInstance.getId())
    .taskDefinitionKey(targetTaskKey)
    .singleResult();

taskService.complete(targetTask.getId());
  1. Service for tasks
  2. finish
taskService.complete(currentTaskId);

This achieves the function of process rollback. Please make appropriate modifications and adjustments according to actual needs.

bannerAds