Order ProcessInstances by StartTime

Hey there!

Is there a way to order running process instances by their starttime?
Unfortunately I didn’t find a ways to access the start time of a running instance, only of historic instances.

Hi,

In cockpit, if you click on the running instances in the circular display on the home page, they are ordered by start date…

regards

Rob

Thanks for the quick answer, I forgot to explicitly mention that I am talking about the Java and REST API

regards
stoetti

Don’t know if it is good practice and if you considered that but we are using the history service for almost every query as it also includes running instances and can be filtered by unfinished:

historyService.createHistoricProcessInstanceQuery().unfinished().orderByProcessInstanceStartTime().list();

The same should work for the REST API, something like that:

GET /history/process-instance?unfinished=true&sortBy=startTime

2 Likes

Good point, that solves my problem.
Although I find it a little weird :tired_face:

Hey, this works only for history process variables, it doesnt work for runtime process variables

The history tables and API include both, archived and runtime processes. Filtering by unfinished=true on the history API would give you the runtime data only. It’s not very elegant as @stoetti pointed out but it works fine.