Java api to fetch all unassigned tasks

I am using passing a variable to my process and instantiating the bpmn process like below.

Map<String, Object> variablesMap = new HashMap<>();
variablesMap.put(“caseNumber”, caseNumber);
// start process model
processEngine.getRuntimeService().startProcessInstanceByKey(“TestProcess”, variablesMap);

first stop of the process is a service task and the second task is a human task.

in the human task I wanted to see all the unassigned tasks. for the I have a Spring rest controller with the below mentioned java code.

List tasklist = processEngine.getTaskService().createTaskQuery().taskUnassigned().orderByTaskCreateTime().desc().list();

when I run that spring rest service I am getting the exception.

ERROR org.camunda.bpm.engine.context - ENGINE-16004 Exception while closing command context: execution 29 doesn’t exist: execution is null
org.camunda.bpm.engine.exception.NullValueException: execution 29 doesn’t exist: execution is null

Any thoughts on this would be great help.

Hi @subbu,

I think the exception is unrelated to the task query. Are you able to reproduce the error in a unit test? See the unit testing template to get started quickly.

Cheers,
Thorben

Hi @thorben
Thanks for the quick response.

Just figured out that the error is thrown while accessing the variables from process instance.

runtimeService.getVariable(task.getExecutionId(), “studentId”);

I used task.getTaskId() instead if task.getExecutionId().

Corrected that and I got the result back.

Regards,
Subbu

1 Like