List all the tasks for a given Process in the order of execution

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

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

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

Hey @madhairsilence,

I see that you already posted the same question on StackOverflow here. Please do not crosspost, we are monitoring both channels.

To answer the question here.


If by tasks you mean all the finished or running 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

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.

In case you are looking to get the tasks in the order of what they would be executed then it needs to be done through the BpmnModel, but the order there is not deterministic.