# Find and access the user task to which my boundary event is attached

**URL:** <https://forum.flowable.org/t/find-and-access-the-user-task-to-which-my-boundary-event-is-attached/3381>\
**Category:** Flowable Engine\
**Created:** [February 4, 2019, 12:31pm UTC](https://forum.flowable.org/t/find-and-access-the-user-task-to-which-my-boundary-event-is-attached/3381 "2019-02-04T12:31:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MohitGupta](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@MohitGupta](https://forum.flowable.org/u/MohitGupta)\
**Post date:** [February 4, 2019, 12:31pm UTC](https://forum.flowable.org/t/find-and-access-the-user-task-to-which-my-boundary-event-is-attached/3381/1 "2019-02-04T12:31:04Z")

</div>

We have a User Task with a Timer Boundary Event. An ExecutionListener is triggered when the timer is fired. The ExecutionListener contains the code to send reminder to task assignee and owner. Also the content and format of the mail depends on the task id. Inside the ExecutionListener, is there a way to find and access the user task to which my boundary event is attached. I am not able to find anyway whatsoever to find the task object from ExecutionListener.

---

<div class="post-metadata">

**Author:** ![aoswald](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/aoswald/32/1331_2.png) [@aoswald](https://forum.flowable.org/u/aoswald)\
**Post date:** [August 20, 2019, 7:41pm UTC](https://forum.flowable.org/t/find-and-access-the-user-task-to-which-my-boundary-event-is-attached/3381/2 "2019-08-20T19:41:51Z")

</div>

Same question as o/p. My attempt involved using Execution listener configuration as such:  
Event: End  
Expression: #{mySpringBean.onTimer(execution.currentFlowElement.attachedToRef)}

That provides the onTimer method with a org.flowable.bpmn.model.UserTask, but I was hoping for something more along the lines of a org.flowable.task.service.impl.persistence.entity.TaskEntity. Specifically, it seems like the UserTask is more like a definition and not an instance.

Flowable folks, how can I/we get the user task instance by way of execution listener expression here?

Thanks!  
-andy

---

<div class="post-metadata">

**Author:** ![aoswald](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/aoswald/32/1331_2.png) [@aoswald](https://forum.flowable.org/u/aoswald)\
**Post date:** [August 22, 2019, 4:08pm UTC](https://forum.flowable.org/t/find-and-access-the-user-task-to-which-my-boundary-event-is-attached/3381/3 "2019-08-22T16:08:54Z")

</div>

Valentin Z. was kind enough to share an answer for this. The skinny of it is is that you need to query the TaskService using the process instance id and the task’s (from which the boundary event is associated) definition key. My prior example expression would then look like:

#{mySpringBean.onTimer(execution.processInstanceId, execution.currentFlowElement.attachedToRefId)}

And the Java code:

void onTimer(String processInstanceId, String taskDefinitionKey) {  
Task task = taskService.createTaskQuery()  
.processInstanceId(processInstanceId)  
.taskDefinitionKey(taskDefinitionKey)  
.singleResult();  
…  
}

Hope that helps anyone else who may need it!
