# Default listener for all tasks (CMMN)

**URL:** https://forum.flowable.org/t/default-listener-for-all-tasks-cmmn/4979
**Category:** Flowable Engine
**Created:** [December 2, 2019, 8:56am UTC](https://forum.flowable.org/t/default-listener-for-all-tasks-cmmn/4979 "2019-12-02T08:56:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![chrisburrell](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chrisburrell](https://forum.flowable.org/u/chrisburrell)
#### Post date: [December 2, 2019, 8:56am UTC](https://forum.flowable.org/t/default-listener-for-all-tasks-cmmn/4979/1 "2019-12-02T08:56:34Z")

</div>

Hi

I was wondering if it’s possible to get flowable to have a generic/default listener for all tasks, without having to wire it in for every single task in the XML configuration - in other words, configuring flowable to fire a listener that can be re-used everywhere but without having to write it in anywhere.

The idea would be to be able to fire off messages to other external services automatically saying “Task X has completed” - being able to do this generically for everything, means we wouldn’t need to be rely on developers to remember

Cheers  
Chris

---

<div class="post-metadata">

### Author: ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)
#### Post date: [December 2, 2019, 9:58am UTC](https://forum.flowable.org/t/default-listener-for-all-tasks-cmmn/4979/2 "2019-12-02T09:58:45Z")

</div>

Hi Chris.

Use the same mechanism as is used for processes:  
[https://www.flowable.org/docs/userguide/index.html#advanced\_parseHandlers](https://www.flowable.org/docs/userguide/index.html#advanced_parseHandlers)

You can configure parse handlers in cmmn engine configuration.

Regards  
Martin

---

<div class="post-metadata">

### Author: ![ASarco](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/asarco/32/1119_2.png) [@ASarco](https://forum.flowable.org/u/ASarco)
#### Post date: [December 3, 2019, 6:22pm UTC](https://forum.flowable.org/t/default-listener-for-all-tasks-cmmn/4979/3 "2019-12-03T18:22:05Z")

</div>

Hi @martin.grofcik , I’m a colleague of Chris and I was trying to implement this.

By stepping through code, I can see that the configuration is modified by adding my taskParseHandler to the postCmmnParseHandler collection, but the parse() method is never called. Therefore, my listener is not being added.  
I’m I doing something wrong, or is there a bug somewhere?

```
@Configuration
@AutoConfigureAfter(CmmnEngineAutoConfiguration.class)
class FlowableConfigurationConfigurer {

    private static final Logger LOGGER = LoggerFactory.getLogger(FlowableConfigurationConfigurer.class);

    @Autowired
    private TaskListener taskListener;

    @Bean
    @ConditionalOnClass(SpringCmmnEngineConfiguration.class)
    public EngineConfigurationConfigurer<SpringCmmnEngineConfiguration> customizeSpringProcessEngineConfiguration() {
        return processEngineConfiguration -> {
            LOGGER.info("Overriding process engine configuration");

            List<CmmnParseHandler> postCmmnParseHandlers = processEngineConfiguration.getPostCmmnParseHandlers();
            if (Objects.isNull(postCmmnParseHandlers)) {
                postCmmnParseHandlers = new ArrayList<>();
            }
            postCmmnParseHandlers.add(new TaskParseHandler() {
                @Override
                public void parse(CmmnParser cmmnParser, CmmnParseResult cmmnParseResult, BaseElement element) {
                    List<ExtensionElement> extensionElements = element.getExtensionElements().get("taskListener");
                    ExtensionAttribute eventAttribute = new ExtensionAttribute();
                    eventAttribute.setName("event");
                    eventAttribute.setValue("complete");
                    ExtensionAttribute delegateAttribute = new ExtensionAttribute();
                    delegateAttribute.setName("delegateExpression");
                    delegateAttribute.setValue("${basicTaskListener}");

                    ExtensionElement extensionElement = new ExtensionElement();
                    extensionElement.setName("taskListener");
                    extensionElement.addAttribute(delegateAttribute);
                    extensionElement.addAttribute(eventAttribute);
                    extensionElements.add(extensionElement);
                    super.parse(cmmnParser, cmmnParseResult, element);
                }
            });
        };
    }

    private Map<String, List<FlowableEventListener>> addEngineEventListeners() {
        Map<String, List<FlowableEventListener>> typedEventListeners = new HashMap<>();
        typedEventListeners.put(FlowableEngineEventType.TASK_CREATED.name(), List.of(taskListener));
        return typedEventListeners;
    }
}

```

Thanks.

---

<div class="post-metadata">

### Author: ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)
#### Post date: [December 5, 2019, 8:45am UTC](https://forum.flowable.org/t/default-listener-for-all-tasks-cmmn/4979/4 "2019-12-05T08:45:35Z")

</div>

It looks like you’re only adding a process task parse handler to the engine (also, you’re not setting the list on the engineConfig when it’s null). For CMMN, you’d need a different implementation, injected into the cmmn engine configuration. You can add these through the #setCustomCmmnParseHandlers method.
