# Process instance id keeps returning null

**URL:** <https://forum.flowable.org/t/process-instance-id-keeps-returning-null/3741>\
**Category:** Flowable Engine\
**Created:** [April 15, 2019, 8:10am UTC](https://forum.flowable.org/t/process-instance-id-keeps-returning-null/3741 "2019-04-15T08:10:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TodoMary](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/todomary/32/1173_2.png) [@TodoMary](https://forum.flowable.org/u/TodoMary)\
**Post date:** [April 15, 2019, 8:10am UTC](https://forum.flowable.org/t/process-instance-id-keeps-returning-null/3741/1 "2019-04-15T08:10:39Z")

</div>

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:

```auto
Map <String, Object> pvar = new HashMap<String,Object>();
				pvar.put("status",200);
				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?

**Edit**

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

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [April 15, 2019, 10:09pm UTC](https://forum.flowable.org/t/process-instance-id-keeps-returning-null/3741/2 "2019-04-15T22:09:09Z")

</div>

> [@TodoMary](#):
>
> 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:

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.

Cheers,  
Filip
