# User Task get Task Listener detail

**URL:** <https://forum.flowable.org/t/user-task-get-task-listener-detail/5932>\
**Category:** Flowable Engine\
**Created:** [April 30, 2020, 5:46pm UTC](https://forum.flowable.org/t/user-task-get-task-listener-detail/5932 "2020-04-30T17:46:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkatesh](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/venkatesh/32/1777_2.png) [@venkatesh](https://forum.flowable.org/u/venkatesh)\
**Post date:** [April 30, 2020, 5:46pm UTC](https://forum.flowable.org/t/user-task-get-task-listener-detail/5932/1 "2020-04-30T17:46:07Z")

</div>

Hello,

I have task listener configured on an User task which will execute on complete event. However, I would like to get the details of this listener using the task object before even this event is triggered to perform some logic. I have the below code which gets me the task details from **org.flowable.engine.TaskService**. But I don’t see any info regarding the listeners on this object.

Task task = taskService.createTaskQuery().processInstanceId( processInstanceId )  
.taskAssignee( taskAssignee )  
.active()  
.singleResult();

Is there any way i could get these details ?

Thanks

---

<div class="post-metadata">

**Author:** ![amporsim](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@amporsim](https://forum.flowable.org/u/amporsim)\
**Post date:** [April 30, 2020, 8:32pm UTC](https://forum.flowable.org/t/user-task-get-task-listener-detail/5932/2 "2020-04-30T20:32:47Z")

</div>

Hi @venkatesh

I think you have to go over the task model:

```
    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId)
            .taskAssignee(taskAssignee)
            .active()
            .singleResult();
    
    if (task.getProcessDefinitionId() != null) {
        org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(task.getProcessDefinitionId());
        FlowElement flowElement = process.getFlowElement(task.getTaskDefinitionKey(), true);
        if (flowElement instanceof UserTask) {
            UserTask userTask = (UserTask) flowElement;
            List<FlowableListener> taskListeners = userTask.getTaskListeners(); 
        }
    }

```

Regards,  
Simon

---

<div class="post-metadata">

**Author:** ![venkatesh](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/venkatesh/32/1777_2.png) [@venkatesh](https://forum.flowable.org/u/venkatesh)\
**Post date:** [April 30, 2020, 9:05pm UTC](https://forum.flowable.org/t/user-task-get-task-listener-detail/5932/3 "2020-04-30T21:05:28Z")

</div>

Thanks so much Simon. This makes sense. I was not aware of how to get the model object given a task. Will try this and update.

---

<div class="post-metadata">

**Author:** ![venkatesh](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/venkatesh/32/1777_2.png) [@venkatesh](https://forum.flowable.org/u/venkatesh)\
**Post date:** [May 1, 2020, 7:19am UTC](https://forum.flowable.org/t/user-task-get-task-listener-detail/5932/4 "2020-05-01T07:19:08Z")

</div>

Hello Simon,

I had to execute the above logic as part of a new command. Other wise got an exception stating " **org.flowable.common.engine.api.FlowableException: Cannot get process model: no current command context is active**". Thank you for providing the solution !

Below is the final code.

```
 try
            {
                taskListeners = processEngine.getManagementService().executeCommand( new Command<List<FlowableListener>>()
                {

                    @Override
                    public List<FlowableListener> execute( CommandContext commandContext )
                    {
                        org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess( task.getProcessDefinitionId() );
                        FlowElement flowElement = process.getFlowElement( task.getTaskDefinitionKey(), true );
                        if( flowElement instanceof UserTask )
                        {
                            UserTask userTask = (UserTask) flowElement;
                            List<FlowableListener> taskListeners = userTask.getTaskListeners();
                            return taskListeners;

                        }
                        return null;
                    }

                } );

            }
            catch( FlowableException fe )
            {
                fe.printStackTrace();
            }
```
