Find ProcessInstance by TaskId always fails


#1

Dear community

I’m quite new to Camunda, currently developing an application with JSF (2.3.7 Mojarra), Spring Boot 2.0.2 and Camunda 7.9 (Community Edition).

I have a very simple process which starts from a JSF Page (Form) attached to the StartEvent using runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);

In the next step of the process I try to fetch the process variables (that I entered on the first form) for approval in a UserTask Form like this:

  1. Getting the taskId from the FacesContext RequestMap in the PostConstruct method of a ViewScoped Backing Bean.

  2. Calling a service method with the following code:
    ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().activityIdIn(taskId);

List processes = processInstanceQuery.list();

However the obtained list is always empty.
As an alternative I also tried this code:

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;

Here superProcessInstance always remains null …

Can anyone help me here? Should I provide more details?

Kind regards & thanks in advance!