Getting the current task

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())
}

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())

Instead of opening a new topic, I ask my question here.

How is the proposed solution different than:

Task task = processEngine.getTaskService().createTaskQuery()
	.processInstanceId(instance.getId())
        .taskDefinitionKey(taskDef)
	.singleResult();

Doesn’t the second option bring the active task of a given name of a given process instance?
My goal is to find whether a given task (i.e., specific task name/definition) is active in a specific process instance.

Thx

1 Like