Get the task instance from a execution listener


#1

I have an execution listener bind to the start of task (start: Java Class). How can I get the task id of this task?

public class WaitForReceiptAlert implements ExecutionListener {

    @Override
    public void notify(DelegateExecution execution) throws Exception {
              // Is null !
              execution.getProcessEngineServices().getTaskService().createTaskQuery().taskId(execution.getId())
     }
}

#2

If you want the task id, it’s probably better to use a Task Listener than an execution listener because the execution listener will run before the task comes into existence.

public class test implements TaskListener {

	@Override
	public void notify(DelegateTask delegateTask) {
		//get the id of the current task
		delegateTask.getId();

	}
}