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

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

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

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 def 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.

5 Replies
Highlighted
Established Member II

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

Hello Mohit,

Maybe you could try to create a variable at the execution level in the creation of the UserTask with

execution.setVariable('actual_assignee', task.assignee) ‍‍‍‍

 and then use it in the ExecutionListener of the Boundary event.

Regards

Highlighted
Member II

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

There are multiple tasks in my process and for almost every type of task there is a generic reminder service that is called. So I'm not sure setting up a variable will solve the use case.

Highlighted
Active Member II

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

You can get the engine services, process intsance Id, current activity Id, etc, from the execution, so you might expect to be able create a Task query and get the task back. However, use of the API within a listener is not recommended and unreliable. When I have tried calling it directly I don't get the results I expect. When I have really needed to use the API in this sort of situation I've ended up using a seperate thread, operating either synchronously or asynchronouslly as required.

Highlighted
Established Member II

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

In this scenario this simple solution is not going to work but i think that the option of use the workflows apis to trying to retrieve the original task is not going to work easily neither in this situation.

Maybe you can increase the complexity of the logic. Somethig like store more info in the execution variables in the user task or use intermediate service tasks for each type of task in which you can make some kind of mark before go to the generic remider service

At the end the number and type of thes task that can use de remainder service are finite and you knows it before the execution of the workflow.

Highlighted
Active Member

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

Hello Mohit,

I found an interesting solution to get the user task to which attached a Boundary Timer Event.
If you create a listener which implements the "ExecutionListner", you will have to implement the method "notify" which has a "DelegateExecution" as a signature parameter. You can then access the desired user task using the "FlowElement":

FlowElement flowElement = execution.getCurrentFlowElement();
Task task = taskService.createTaskQuery()
.taskDefinitionKey(((BoundaryEvent) flowElement).getAttachedToRef().getId())
.processInstanceId(execution.getProcessInstanceId())
.singleResult();

Then you can access the task with its data.  Smiley Happy