Field injection with Execution Listener

I am trying to implement a Listener with a field injection.

I call a ExecutionListener via Delegate Expression, which is found correctly. I set a Field Injection field with a name, as Type String, with a value.

In my code the injection is referenced to as Type Expression. I try to call the String value with getValue(execution).toString();in the Listeners notify-method, but i always get a NullPointerException, because the injected Object is always null.

Any Ideas of why this fails? I´ve done field injections often with service or send tasks but never with listeners. Is there any difference i should be aware of?

Thx in advance!

I did a workaround by using an expression instead. But it seems ugly.

Hi @BenF,

Have you followed the documentation here: https://docs.camunda.org/manual/latest/user-guide/process-engine/delegation-code/#field-injection when configuring the field injection?

If yes, can you provide the code and bpmn process, or at least the part that relates to the problem?

Best,
Nikola

Hi all, it’s an older post but I needed the same functionality for ExecutionListener and ended up with NPEs. @nikola.koevski 's note to follow the documentation was the key to solve the issue:
You have to use the type Expression for the injected field even if you inject just a String. Then you can call:

fieldName.getValue(execution).toString();

One should still check against NPs if the same Listener is used in the BPMN without field injection or injection result depends on other variables etc.

1 Like