问题
Actually i want to use the previous task name in current task so how to get the previous task name in current task in activiti. If any one knows could you help me?
eg:TASK1==>TASK2==>TASK3
i want to use the task1 name in task2 and task2 name in task1.
回答1:
You can get it from your current Process Instance:
@Service
public class SomeWorkflowService {
@Autowired
HistoryService historyService;
@Autowired
TaskService taskService;
public Map<String, Object> currentTaskService(String currentTaskId) {
Map<String, Object> taskMap = new HashMap<>();
Task currentTask = taskService.createTaskQuery().taskId(currentTaskId).singleResult();
HistoricTaskInstance previousTask = findPreviousTask(currentTask.getProcessInstanceId());
taskMap.put("Current task name: ", currentTask.getName());
taskMap.put("Previous task name: ", previousTask.getName());
return taskMap;
}
// Order tasks by end date and get the latest
public HistoricTaskInstance findPreviousTask(String processInstanceId) {
return historyService.createHistoricTaskInstanceQuery().
processInstanceId(processInstanceId).orderByHistoricTaskInstanceEndTime().desc().list().get(0);
}
}
There maybe some issues with this kind of simple algorithm. For example, I have multiple subprocesses in application, or there may be parallely executed tasks, then I'm using more complex algorithm to find previous task.
来源:https://stackoverflow.com/questions/17652175/how-to-get-the-previous-task-name-in-activiti-workflow