how to get the previous task name in activiti workflow

让人想犯罪 __ 提交于 2019-12-11 01:54:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!