1

This is a basic functionality and I see repeated questions , but unfortunately no clear answer yet.

How do I print/list all the tasks in the given process ( finished / unfinished ) in the order of execution.

The two solution I found on the forum are working as expected

repositoryService.getBpmnModel().getFlowElements() - Does not print in the order of execution . Printed in the order of definition
historyService.createHistoricActivityQuery - Does not print all Service task

How do I just list all the task under the given process.

madhairsilence
  • 3,787
  • 2
  • 35
  • 76
  • Can you please help me to solve my question: https://stackoverflow.com/q/60925265/6097074 – ankit Mar 30 '20 at 09:11

2 Answers2

0

If by tasks you mean all the elements in the process then you can use the HistoricActivityInstanceQuery to get the information about them.

The code would look something like:

List<HistoricActivityInstance> activityInstances = historyService
    .createHistoricActivityInstanceQuery().
    .processInstanceId(processInstanceId)
    .orderByHistoricActivityInstanceStartTime().asc()
    .list();

In order to see if a HistoricActivityInstance is finished or not you'll need to check the HistoricActivityInstance#getEndTime(). When that is null it means that the activity is not finished, if it is null then it means it is finished.

Filip
  • 19,269
  • 7
  • 51
  • 60
  • This is not returning all the tasks. I can startEvent, sequenceFlow and the first UserTask – madhairsilence Oct 09 '19 at 06:26
  • 2
    This is returning all the tasks that were / are executing for a given process instance. If you are looking into the order in which they will be executed then I misunderstood the question – Filip Oct 09 '19 at 06:33
  • yeh. My Mistake sorry. I could see all the tasks getting printed. And I also , see the order is also correct. Is this order dependable or it is based on how bpmn is written – madhairsilence Oct 09 '19 at 06:54
  • 1
    The order that you will get from the `HistoricActivityInstnaceQuery` is the one you requests in the query. In this example it is the order of which the tasks were started – Filip Oct 09 '19 at 06:56
  • Sorry to bump. Just a confusion. The HistoricActivity list, only tasks that are complete and the next task alone. Support i have task 1 - 4. And if the tasks 1,2 are complete, then I can see only task 1, task 2 and task 3, but not task 4. If i finish task 3, i can see task 4. So as a whole the historic activity displayed [ executed + next task ]. How to I get the full list of tasks – madhairsilence Oct 09 '19 at 08:20
  • The list contains all completed tasks and all started tasks. It doesn't have anything about future tasks. All tasks from a process can be retrieved via the `BpmnModel`, but not in an execution order – Filip Oct 09 '19 at 13:08
  • so I guess. There aint no API to get all the tasks in the order of execution. This can be worked around by writing the BPMN in the correct order – madhairsilence Oct 10 '19 at 07:59
  • The problem is that there is no correct oder. You can have cycles, parallel gateways, exclusive gateways etc – Filip Oct 10 '19 at 11:07
  • Makes sense.. so if can add one more question. If I have to display the complete workflow as a visualization for the user upfront, what do you suggest? – madhairsilence Oct 10 '19 at 14:17
  • If you want to see the workflow I would suggest that you look at https://github.com/flowable/flowable-engine/blob/master/modules/flowable-ui-admin/flowable-ui-admin-app/src/main/resources/static/display/bpmn-draw.js. That is used in the Flowable UI Applications – Filip Oct 11 '19 at 08:57
-1

You can create a TaskQuery

import org.camunda.bpm.engine.ProcessEngine;
...

@Autowired
private ProcessEngine processEngine;

private List<Task> getAllTaskByProcessId(string processInstanceId){
  return processEngine.getTaskService()
    .createTaskQuery()
    .processInstanceId(processInstanceId)
    .list();
}

ehmkey
  • 188
  • 1
  • 14