Not able to get processInstance details inside a listener

I’m trying to write a ProcessCompletedListener using flowable events.

Now inside the event, I’m trying to access variables associated with the processInstanceId.
To do that I tried to get the processDefinitionId using runtimeService and historicService. But both of these services are returning null.

    // Completed process, returns null; expected process is still running
    HistoricProcessInstance process = processEngine.getHistoryService().createHistoricProcessInstanceQuery()
            .processInstanceId(procInstanceId).singleResult();

    // Why is runtimeService also returning null ? 
    ProcessInstance processInstance = processEngine.getRuntimeService()
            .createProcessInstanceQuery()
            .processInstanceId(procInstanceId)
            .singleResult();

Getting processDefintionID was the first step in my process to get the variables associated with the processInstance. What service should I query in order to get processInstance variables/other-meta(processDefintionName, deploymentId) etc… inside a flowableEvent onEvent?

I have isFailOnException = true, isFireOnTransactionLifecycleEvent = false, getOnTransaction = null as override values for the event.

I found a work around, keeping isFireOnTransactionLifecycleEvent = true with getOnTransaction = “COMMITTED” worked for me.

Is there documentation detailing the getOnTransaction and it’s lifecycle?
I found some @ https://flowable.com/open-source/docs/bpmn/ch03-Configuration/#event-listener-implementation

The runtimeService query won’t check the cache. When the listener gets executed, the data hasn’t been committed yet to the database. That’s why it works when using the committed onTransaction event (but the listener will now not be part of the same database transaction).

You can query for the current execution in the listener and get the variables through the getVariable() methods. This depends on the type of listener. Can you post how the implementation for ProcessCompletedListener looks like?