Get User Task of Timer Boundary Event

Hi all,

I modeled a User Task with a Non Blocking Timer Boundary Event. An ExecutionListener is triggered when the timer is fired. Inside the Timer ExecutionListener code I would like to get a handle to the task to which the timer is attached. This must be possible somehow (because blocking timer are able to interrupt the parent activity), but I had no luck with execution.getParentId() or execution.getParentActivityInstanceId() when trying to get the task execution id. I always only get the ID of the process instance.

Seems not so easy to get a handle to the task instance that is attached to the timer (see also this forum post). Is it really that hard? How can I do it?

Thanks and kind regards,
Franz

1 Like

Do you mean with handle to the task the id of the user task in the BPMN XML?

I would like to get a handle to the User Task instance to obtain task parameters like dueDate and followUpDate (e.g. to check if a Date is already reached.).

Something like this might work

public void notify(DelegateExecution execution) {
  ManagementService managementService = ..;
  TaskService taskService = ..;

  Job timerJob = managementService.createJobQuery().processInstanceId(execution.getProcessInstanceId()).activityId(execution.getCurrentActivityId()).singleResult();
  Task task = taskService.createTaskQuery().executionId(timerJob.getExecutionId()).singleResult();
}

Note that both job and task can be null if the task has been completed/cancelled in the meantime.

Cheers,
Thorben

Edit: The job query only works if this task is active only once per process instance. I don’t think there is a good way to get this in the general case, as there is no connection between the execution executing the execution listener and the execution representing the user task activity instance.

That works great. Thanks!

A question to your edit remark: What do you mean by “task is active only once per process instance”. How could a task be active more than once? By repetition? Or is there another case where this is possible? And if so, would the executionId of the timer not change in this case and lead to another task instance?

Thanks. Note that I edited my answer and the code so that it works with multiple process instances.

I have a similar use case, but am having trouble with this approach.

We are currently assigning many subprocess out that have a user task in them (via an exclusive gateway). We want a reminder email to kick off every day, so we have a boundary timer event on the user task that has a custom Execution Listener.

We are unable to get the user task ID in the listener. This seems like something that should be available, as it is attached to the task at the boundary.

I tried he approach above, but it returns all boundary event jobs, not just one. Is there really no link between a boundary timer event and a user task it is associated with?

1 Like

I think I’m in the same situation here.

Most of the time @thorben solution will work, but it does not really relate to task and its boundary events, it’s a simplistic consideration, like he said.

I agree that both the rest and api are missing these important informations for boundary events, or it is extremely painful to get such a relation.