Get the root execution/processInstance for a given task

Given only a taskId is it possible to get the “root” execution or “root” processInstance?

That means in case the task belongs to a sub process (or a call activity) - is there any change to get the overall “root” process that belongs to this task?

I did not find any way using the ProcessInstanceQuery or ExecutionQuery and their results to find “super Executions” (as it is possible for DelegateExecutions for example).

Hi Franz,

there is no API to get the root process instance of a task directly. But you can build this by your own, for example:

Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
String processInstanceId = task.getProcessInstanceId();

ProcessInstance superProcessInstance = null;
do {
  superProcessInstance = runtimeService.createProcessInstanceQuery().subProcessInstanceId(processInstanceId).singleResult();
  if (superProcessInstance != null) {
    processInstanceId = superProcessInstance.getId();
  }
} while (superProcessInstance != null);

String rootProcessInstanceId = processInstanceId;

Does this help you?

Best regards,
Philipp

2 Likes

Hi Philipp,

thanks. That is what I was looking for.

Kind regards and good luck in 2017
Franz

1 Like