AnsweredAssumed Answered

Problems adding TaskListener from ParseHandler

Question asked by felipe1 on Nov 27, 2013
Latest reply on Dec 13, 2013 by frederikheremans1
I'm trying to add custom a TaskListener to every UserTask declared in my processes.

I have looked at this bit of the documentation ( to get me started.

I have also found this example of Handler that insert a custom handler to UserTasks -

So I created the class shown below. It seems that I have did everything according to the documentation, however it is not working.  The problem is that I cannot get a reference to a TaskDefinition object.

I assumed that The ProcessDefinitionEntity#getTaskDefinitions() method would return all the tasks defined in the current process, then it would be easy to get the task with the taskDefinitionKey, but that is not the case.

When I open an external start form, the parse() method is called 3-4 times, and the return from the getTaskDefinitions() method is different on every call.

public class CustomParse implements BpmnParseHandler {

   public Collection<Class<? extends BaseElement>> getHandledTypes() {
      List<Class<? extends BaseElement>> elements = new ArrayList<>();
      return elements;

   public void parse(BpmnParse bpmnParse, BaseElement element) {
      String taskDefinitionKey = element.getId(); // returns the correct task key
      Map<String, TaskDefinition> tarefas = ((ProcessDefinitionEntity) bpmnParse.getCurrentScope().getProcessDefinition()).getTaskDefinitions();
      for(Entry<String, TaskDefinition> e : tarefas.entrySet()) {
         System.out.println("****************** " + e.getKey() + " :: " + e.getValue());
      TaskDefinition taskDefinition = ((ProcessDefinitionEntity) bpmnParse.getCurrentScope().getProcessDefinition()).getTaskDefinitions().get(

      if (taskDefinition != null) { // taskDefinition is always null at this point
         taskDefinition.addTaskListener(TaskListener.EVENTNAME_CREATE, new CustomTaskListener());