GetProcessVariables --- Task integration between Flowable and ERP system

[Flowable newbie]

We are currently building an automated workflow on top of an existing ERP system.
The requirements are relatively simple:

  1. Every time a User Task gets instantiated as part of a process execution, an equivalent (and linked) Task ‘object’ is created in the ERP.
  2. Point 1 should be totally transparent to BPMN process authors.

I managed to make it work.
I’m implementing the FlowableEventListener interface and filtering on the TASK_CREATED event type in the onEvent method.

However, when replicating the ERP Task (from the User Task) I need to fetch process instance level variables. I do that by calling getProcessVariables() which consistently yields nothing.

public void onEvent(FlowableEvent ev) {
    if ((FlowableEngineEventType) ev.getType() == FlowableEngineEventType.TASK_CREATED) {
        FlowableEngineEntityEvent event = (FlowableEngineEntityEvent) ev;
        Task task = (Task) event.getEntity();

        Map vars = task.getProcessVariables();
        // vars is empty .. where are my variables :-(

What am I doing wrong? Do I, instead, have to use runtimeService to re-query for process instance level variables?

Many thanks.

The getProcessVariables() returns variables only when you used a TaskQuery (the javadoc on the getProcessVariables method hints at that),

To get the variables at that point, you could chose to cast to TaskEntity and call #getVariables(). Alternatively, if you don’t want to cast to TaskEntity, you need to get the variables through the runtimeService#getVariables passing the processInstanceId of the Task.