Get Task Assignee Details in ExecutionListener

cancel
Showing results for 
Search instead for 
Did you mean: 
eramesh
Active Member

Get Task Assignee Details in ExecutionListener

Hi,

We are using Enterprise Activiti 1.5, I'm trying get the assignee details in the java code that's invoked from "ExecutionListener" of the User Task but not able to get it.

I'm able to get the assignee details in the java code using "TaskListener" of the User Task like below,

String assignee = delegateTask.getAssignee()

Is it possible to get the assignee details in "ExectionListener"? Please let me know.

Thanks!

2 Replies
thuynh
Established Member II

Re: Get Task Assignee Details in ExecutionListener

Hi eramesh _ ,

Did you set the candidate users for the user task? 

For example, 

<userTask id="task" name="My Task" activiti:candidateUsers="${ldapService.findAllSales()}"/>

Then, if the assignee is within the candidate users, delegateTask.getAssignee() should return the Assignee correctly.

Thanks,

Thong Huynh

thuynh
Established Member II

Re: Get Task Assignee Details in ExecutionListener

HI eramesh _ ,

Apologies, I didn't notice that you were specifically referring to ExecutionListener. 


Did you try this?

public class MyExecutionListener implements ExecutionListener {

Logger logger = Logger.getLogger(MyExecutionListener.class);

public void notify(DelegateExecution execution) throws Exception {
// TODO Auto-generated method stub
logger.info("Execution, task assignee: " +
execution.getEngineServices()
.getTaskService().createTaskQuery()
.processInstanceId(execution.getProcessInstanceId()).singleResult().getAssignee());
}

}

As an alternative, you can create TaskListener to handle more actions upon task events, here's an example

public class MyTaskCreateListener implements TaskListener {

Logger logger = Logger.getLogger(MyTaskCreateListener.class);

public void notify(DelegateTask delegateTask) {
// Custom logic goes here
logger.info("User task is created.");
logger.info("Listener executed.");
logger.info("Delegate Task assignee: " + delegateTask.getAssignee());
DelegateExecution execution = delegateTask.getExecution();
RuntimeService runtimeService = execution.getEngineServices().getRuntimeService();
runtimeService.signalEventReceived("EMAIL_SUPPORT_SIGNAL");
}
}

Thanks,

Thong Huynh