Process instance id keeps returning null

I’m having problems retrieving objects using process instance id.
I perform a GET request to get all process instances id’s that I ran, take one and try to use it for some operations, but they always fail because of one of these reasons:

1- the task returned by process instance id is null, or
2- the execution with specified process instance id does not exist

In detail, in the first case I’m doing this:

org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId("e3ada504-5ba5-11e9-ac0e-d46d6dbfea92").singleResult();
		System.out.println("Task information " + task.getCategory()
				+ " - "  + task.getName() + " - " + task.getClass() + " - " + task.getScopeType());

but a NullPointerException is thrown because task is null.
In the other case, I’m trying to get the map of variables but it throws an error:

execution <processInstanceId> doesn't exist

I’ve followed the test code on github and wrote:

Map <String, Object> pvar = new HashMap<String,Object>();
				pi = runtimeService.startProcessInstanceById(processDefinitionId, pvar);

then I try to get the map again and

Map<String,Object> variables = runtimeService.getVariables(pi.getId());

and the error is thrown.
What am I missing? Why I can’t get the informations? What’s the correct way to use the processInstanceId?


This does not happen always. With some process instances it does work and do not throw Nullpointerexception. I don’t get the reason why

Which GET endpoint are you invoking for this?

Flowable has the concept of RuntimeService and HistoryService. The first one contains only the runtime data (what is currently active) and the second one has all the data. The runtime data is a subset of the history data.

The reason why you can’t find some tasks / variables via the RuntimeService is due to the fact that either the task is completed or the process is completed.


1 Like