AnsweredAssumed Answered

Get active process Instances with associated tasks

Question asked by sam_a on May 22, 2017
Latest reply on May 23, 2017 by sam_a

I have a requirement to get the list of all active instances along with the tasks under every instance. I did the below but unable to retrieve the tasks under the instance. Appreciate any pointers.

 

//Get the list of all active process instances

List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().active().list();

 

//Iterate through the instances and cast it to ExecutionEntity to get more info.

for(ProcessInstance processInstance : data) {
    ExecutionEntity entity = (ExecutionEntity)processInstance;
    for(TaskEntity task : entity.getTasks()) {
      ...
    }
}

While performing entity.getTasks(), it throws a NPE.

java.lang.NullPointerException: null
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.ensureTasksInitialized(ExecutionEntity.java:1391)

Looks like Context.getCommandContext() inside the ensureTasksInitialized method is returning null.

 

How do I get around this problem? Isn't the correct way of retrieving the tasks under an instance?

Outcomes