How to get process variables inside custom history event handler

Hi folks,

I am trying to implement a custom event handler which I will then supply to CompositeDbHistoryEventHandler to enable sending some information and email at end of process instance.
I plan to use “if (historyEvent.isEventOfType(HistoryEventTypes.PROCESS_INSTANCE_END)” to ensure its the process instance end event.

I need to use some process variable values to determine the content of email to be sent. The only variable I have access to inside the public void handleEvent(HistoryEvent historyEvent) { } funtion is the historyEvent. I am wondering if there is a way to get processVariable information by using this variable. Basically how do I get the DelegateExecution instance for the instance in which this event occurred?

Thanks,
Akhil.

It would be great if I can see an example too.

Hi @Akhil_Ahuja,

I think instead of a custom HistoryEventHandler, an ExecutionListener is better suited for the job. Note that an execution listener can also be registered on process level, so an end execution listener will be called when the process instance finishes. Then, the execution listener callback gives you access to DelegateExecution. If you need the listener to be executed for all process instances, check out the following example of how to use a parse listener that programmatically registers an execution listener: https://github.com/camunda/camunda-bpm-examples/tree/master/process-engine-plugin/bpmn-parse-listener

Cheers,
Thorben