So this is a method that you can use directly and maybe write it down later

Parameter: taskId: indicates the process ID. DestTaskKey: indicates the target node. TaskName is defined by the taskName of the node in the flowchart

Activiti services used: historyService runtimeService taskService

/** * @param taskId act_ru_task.id * @param destTaskkey Target to rollback taskName */ private void rollbackMoreLeader(String) taskId, String destTaskkey) { try { Map<String, Object> variables; HistoricTaskInstance currTask = historyService .createHistoricTaskInstanceQuery() .taskId(taskId).singleResult(); if (currTask ! = null) { ProcessInstance instance = runtimeService.createProcessInstanceQuery() .processInstanceId(currTask.getProcessInstanceId()).singleResult(); If (instance == null) {system.out.println (" Process terminated!" ); } else { variables = instance.getProcessVariables(); ProcessDefinitionEntity definition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(currTask.getProcessDefinitionId()); If (definition == null) {system.out.println (" Process definition not found!" ); } else {ActivityImpl currActivity = ((ProcessDefinitionImpl) definition) .findActivity(currTask.getTaskDefinitionKey()); System.out.println("currentActivity: " + currActivity); / / a node on the activity List < PvmTransition > nextTransitionList = currActivity. GetIncomingTransitions (); // Empty the exit of the current activity List<PvmTransition> oriPvmTransitionList = new ArrayList<PvmTransition>(); / / the new node connection relationship set List < PvmTransition > pvmTransitionList = currActivity. GetOutgoingTransitions (); for (PvmTransition pvmTransition : pvmTransitionList) { oriPvmTransitionList.add(pvmTransition); } pvmTransitionList.clear(); NewTransitions = new ArrayList<TransitionImpl>(); for (PvmTransition nextTransition : nextTransitionList) { PvmActivity nextActivity = nextTransition.getSource(); System.out.println("nextActivity: " + nextActivity); System.out.println("ProcessDefinition" + nextActivity.getProcessDefinition()); if (nextActivity.toString().contains(destTaskkey)) { ActivityImpl nextActivityImpl = ((ProcessDefinitionImpl) definition) .findActivity(destTaskkey); TransitionImpl newTranstion = currActivity.createOutgoingTransition(); newTranstion.setDestination(nextActivityImpl); newTransitions.add(newTranstion); } else { continue; }} / / Task List < Task > tasks. = taskService createTaskQuery () processInstanceId (the instance. The getId ()) .taskDefinitionKey(currTask.getTaskDefinitionKey()).list(); for (Task task : tasks) { taskService.complete(task.getId(), variables); historyService.deleteHistoricTaskInstance(task.getId()); } for (TransitionImpl TransitionImpl: newTransitions) { currActivity.getOutgoingTransitions().remove(transitionImpl); } for (PvmTransition pvmTransition : oriPvmTransitionList) { pvmTransitionList.add(pvmTransition); } system.out. println(" retract to "+ destTaskkey); } } } } catch (Exception e) { // TODO: handle exception System.out.println(e.getMessage()); }}Copy the code