FlowableEventListener for Process Completion not giving variables

I have configured a FlowableEventListener. The issue I am seeing is that the getProcessVariables always returns 0.

  • I start the process with variables, I can see them in database
  • I complete human task and process ends.
  • My expectations are that the process variables would be avaliabe in following code, but logs show otherwise:
    2019-07-31 12:42:41.696 INFO [gpa-workflow-service,6f6378718b3cb6fc,6f6378718b3cb6fc,false] 20621 — [ XNIO-1 task-4] .m.g.w.e.l.ProcessCompletedEventListener : Process Completed Listener : 0

Listener Stub:

@Slf4j
@Service
class ProcessCompletedEventListener implements FlowableEventListener {

@Override
void onEvent(FlowableEvent event) {
    FlowableEntityEventImpl flowableEntityEvent = (FlowableEntityEventImpl) event
    ProcessInstance processInstance = (ProcessInstance) flowableEntityEvent.entity

    log.info("Process Completed Listener : ${processInstance.getProcessVariables().size()}")

}

@Override
boolean isFailOnException() {
    return false
}

@Override
boolean isFireOnTransactionLifecycleEvent() {
    return false
}

@Override
String getOnTransaction() {
    return null
}

}indent preformatted text by 4 spaces

Here is my config the binds the listeners:

@Component
class FlowableConfigurationConfigurer implements 
EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {

@Autowired
@Lazy
TaskCreatedEventListener taskCreatedEventListener

@Autowired
@Lazy
TaskCompletedEventListener taskCompletedEventListener

@Autowired
@Lazy
ProcessCompletedEventListener processCompletedEventListener

@Override
void configure(SpringProcessEngineConfiguration engineConfiguration) {
    //IDM Service
    engineConfiguration.setIdmEngineConfigurator(new CustomIdentityConfigurator())
    //Engine Event Listeners
    engineConfiguration.typedEventListeners = addEngineEventListeners()

}

private LinkedHashMap<String, List<FlowableEventListener>> addEngineEventListeners() {
    Map<String, List<FlowableEventListener>> typedEventListeners = [:]
    typedEventListeners.put(FlowableEngineEventType.TASK_CREATED.toString(), [taskCreatedEventListener])
    typedEventListeners.put(FlowableEngineEventType.TASK_COMPLETED.toString(), [taskCompletedEventListener])
    typedEventListeners.put(FlowableEngineEventType.PROCESS_COMPLETED.toString(),
                            [processCompletedEventListener])
    typedEventListeners
}

}

Also should note that the TASK_COMPLETED listener has the variables.

getProcessVariables() only works when doing a query, see the javadoc on it:

/**
* Returns the process variables if requested in the process instance query
*/

To get the variables you can cast it to a DelegateExecution and do .getVariables()

Cast works.

Thanks,

Todd