cancel
Showing results for 
Search instead for 
Did you mean: 

listen to events when a task is conplete

viggo_navarsete
Champ in-the-making
Champ in-the-making
Hi. How do I listen for tasks being completed, and how can I differentiate between the various tasks that might exist for a process definition?
1 REPLY 1

balsarori
Champ on-the-rise
Champ on-the-rise
Check out the 3.18. Event handlers section of the user guide

http://activiti.org/userguide/index.html

To be notified only when a task completes, set the typedEventListeners property of processEngineConfiguration to a Map with a key TASK_COMPLETED and value of List containing your class that implements org.activiti.engine.delegate.event.ActivitiEventListener. Your class's onEvent method will get called with an instance of org.activiti.engine.delegate.event.ActivitiEvent each time a task completes.

The ActivitiEvent has a getProcessDefinitionId that you can use to differentiate between different process definitions. To differentiate between tasks, cast ActivitiEvent to org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl. You can then get the task instance using the getEntity method of ActivitiEntityEventImpl (which, of course, you will need to cast). From the task instance you can use the task name or task definition key to differentiate between tasks.