Getting the current task


#1

So far I’ve been able to get the list of active task. Is there a query to get the current task which is supposed to be ‘CustomerOrderTask’(usertask) to complete it without getting all the active task of the instance.

ProcessInstance instance = runtimeService.createProcessInstanceByKey("processOne")
				  .startBeforeActivity("CustomerOrderTask")
				  .execute();

List<Task> tasks = processEngine.getTaskService().createTaskQuery().active()
				.processInstanceId(instance.getId()).list();
		
for(Task task : tasks){
    //maybe compare task name before triggering complete
    //taskService.complete(task.getId())
}

#2

How is active task different from “current task”?

How about:

Task task = processEngine.getTaskService().createTaskQuery()
	.active()
	.taskName("CustomerOrderTask")
	.processInstanceId(instance.getId())
	.singleResult();

processEngine.getTaskService().complete(task.getId())