# EventListener for ALL tasks

**URL:** <https://forum.camunda.io/t/eventlistener-for-all-tasks/47285>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [August 31, 2023, 12:07pm UTC](https://forum.camunda.io/t/eventlistener-for-all-tasks/47285 "2023-08-31T12:07:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draakzward](https://forum.camunda.io/user_avatar/forum.camunda.io/draakzward/32/23660_2.png) [@Draakzward](https://forum.camunda.io/u/Draakzward)\
**Post date:** [August 31, 2023, 12:07pm UTC](https://forum.camunda.io/t/eventlistener-for-all-tasks/47285/1 "2023-08-31T12:07:55Z")

</div>

Good day,

I decided to try and make my life a bit easier and add a `@EventListener` for every task, which is being executed during the flow. I found this topic - [Global event listener on Process Engine Server - #4 by aravindhrs](https://forum.camunda.io/t/global-event-listener-on-process-engine-server/8355/4), and although it covers a good portion of the question, I realized that those listeners DO NOT capture script/service tasks.

It’s nothing special, just a

```auto
@EventListener
	@Order (1)
	public void printTaskEvent(DelegateTask delegateTask) {
		
		log.info("Executing task: {} ({}), action: {}", delegateTask.getTaskDefinitionKey(), delegateTask.getName(), delegateTask.getEventName());
	}

```

So here’s my question of the day - is there a way to listen to all tasks, which are being executed. In particular, script tasks. The reason for this is that my bpmn model is a bit not on the small side, and contains sections with script tasks, following each other.

And every time when something goes wrong, COMPUTER says “There was an exception in a script”, which leaves me with the joyful opportunity to guess WHICH ONE made my day.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![hassang](https://forum.camunda.io/user_avatar/forum.camunda.io/hassang/32/16498_2.png) [@hassang](https://forum.camunda.io/u/hassang)\
**Post date:** [September 1, 2023, 4:40pm UTC](https://forum.camunda.io/t/eventlistener-for-all-tasks/47285/2 "2023-09-01T16:40:01Z")

</div>

Hi @Draakzward,

**Task listener** can only be used with user tasks.  
**Execution listener** can be used with all activity types including service/script tasks.

[Process Application Event Listeners | docs.camunda.org](https://docs.camunda.org/manual/7.19/user-guide/process-applications/process-application-event-listeners/#:~:text=Task%20Event%20listeners%20allow%20to,and%20Transitions%20are%20being%20taken).

> Task Event listeners allow to react to Task Events (Tasks are Created, Assigned, Completed). Execution Listeners allow to react to events fired as execution progresses through the diagram: Activities are Started, Ended and Transitions are being taken.

---

<div class="post-metadata">

**Author:** ![Draakzward](https://forum.camunda.io/user_avatar/forum.camunda.io/draakzward/32/23660_2.png) [@Draakzward](https://forum.camunda.io/u/Draakzward)\
**Post date:** [September 4, 2023, 11:47am UTC](https://forum.camunda.io/t/eventlistener-for-all-tasks/47285/3 "2023-09-04T11:47:16Z")

</div>

@hassang thank you for your response.

But isn’t `@EventListener` an Event listener?.. ah, Event and Execution are different words. Sorry, Monday 😉

---

<div class="post-metadata">

**Author:** ![Draakzward](https://forum.camunda.io/user_avatar/forum.camunda.io/draakzward/32/23660_2.png) [@Draakzward](https://forum.camunda.io/u/Draakzward)\
**Post date:** [September 5, 2023, 2:42pm UTC](https://forum.camunda.io/t/eventlistener-for-all-tasks/47285/4 "2023-09-05T14:42:33Z")

</div>

@hassang can you please point me to how an ExecutionListener can be implemented in terms of Camunda 7 Spring Boot? I feel like I’m missing something

---

<div class="post-metadata">

**Author:** ![Draakzward](https://forum.camunda.io/user_avatar/forum.camunda.io/draakzward/32/23660_2.png) [@Draakzward](https://forum.camunda.io/u/Draakzward)\
**Post date:** [September 5, 2023, 3:05pm UTC](https://forum.camunda.io/t/eventlistener-for-all-tasks/47285/5 "2023-09-05T15:05:34Z")

</div>

For someone looking for this, found this to be the right way to go

```auto
	@EventListener
	public void listen1(ExecutionEvent obj) {
		
		System.out.println("$$$$$$$$$$$$$$$$$$$4");
	}
	
	@EventListener
	public void listen1(ProcessInstance obj) {
		
		System.out.println("$$$$$$$$$$$$$$$$$$$4");
	}

```

Generally, I started with `listen(Object obj)` to determine what type of class I need (not a strong Spring Boot event guy, so sorry for the blasphemy).

Also found in some doc (not yet tested it without these conf lines):

```auto
camunda.bpm.eventing.execution: true
camunda.bpm.eventing.history: true
camunda.bpm.eventing.task: true
camunda.bpm.eventing.skippable: true

```

---

<div class="post-metadata">

**Author:** ![Draakzward](https://forum.camunda.io/user_avatar/forum.camunda.io/draakzward/32/23660_2.png) [@Draakzward](https://forum.camunda.io/u/Draakzward)\
**Post date:** [September 8, 2023, 12:17pm UTC](https://forum.camunda.io/t/eventlistener-for-all-tasks/47285/6 "2023-09-08T12:17:47Z")

</div>

@hassang  
Still can’t get a grip on how to get the scripts.

Going for

```auto
@EventListener
void print(Object obj)

```

got me close to solving this via `HistoricActivityInstanceEventEntity`, but I can’t get information about the script that is being executed (inline/resource). And I’m currently in a situation, where “something” is giving me (a headache) a NPE in console (Sorry Dave, but I can’t tell you which one), and the flow has several scripts as input params in a line.

Any ideas?

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [September 15, 2023, 12:18pm UTC](https://forum.camunda.io/t/eventlistener-for-all-tasks/47285/7 "2023-09-15T12:18:16Z")

</div>

Closed on September 15, 2023, 12:18pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
