Get all active process instance ID for assignee

Hi,

I want to get all active processInstance IDs for any given assignee. I want to know to which all processes he/she was involved with current process status(currently storing this process progress status in separate table along with process ID).Basically, I want to list user all the requests(processIds) in which he was/is involved with current status.

  1. Is there a better approach of storing current status ?
  2. How to get active process instance ID for any given assignee so that by using this processinstanceID, I can get all request from our own table.

Please guide.

Thanks,
Amit Shukla

Hi Amit,

There’s the involvedUser option in the ProcessInstanceQuery, but that also includes the user that started the process and was involved in other tasks. You could also use the TaskQuery and get a list of all active user tasks for a specific assignee and filter the result for the list of process instance ids.
It depends on what kind of status you are storing. If the status is based on user tasks then this info is also stored in the history tables in Flowable. If not, then your approach works fine.

Best regards,

Tijs

List<Task> tasks = taskService.createTaskQuery().taskAssignee(assignee).list();
List<String> processIds = new ArrayList<>();
for(Task t : tasks) {
      processIds.add(t.getProcessInstanceId());
}
return processIds;	

I am getting processInstanceIds from this. Is this right???

Also I have observed, when a task is completed the task is removed from table ‘ACT_RU_TASK’ and new taskID is created with assignee depending on workflow created. The task that was completed is found in table ‘ACT_HI_TASKINST’. So I want to get list of processInstanceIds in which assignee was involved which could be found in table ‘ACT_HI_TASKINST’. Table ‘ACT_RU_TASK’ contains only current running task.

So will the above query return processInstanceIds from table ‘ACT_HI_TASKINST’ ???

Hi,

Yes that code is correct, although I would use a Set instead of a List, because there could be multiple tasks for the same process instance.

If you want to do this on the historic task table, because you want to include completed tasks, then you should use the HistoryService and then the HistoricTaskInstanceQuery. The code you included in your post will do a query against ACT_RU_TASK.

Best regards,

Tijs

1 Like

Thanks for quick reply.

I hope you meant this query

historyService.createHistoricTaskInstanceQuery().taskAssignee(assignee).list();

This will return tasks assigned to a given assignee from ‘ACT_HI_TASKINST’ table as it contains completed tasks as well.

I completely agree there could be multiple tasks assigned to same assignee in one process. In that case this query will return different taskIds with same processIds.

Yes, that’s the correct query.

Best regards,

Tijs