Reference id is erased for historical plan item instance

Hello,

I’ve designed a CMMN case that contains a ProcessTask referencing a BPMN workflow:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/cmmn" xmlns:cmmndi="http://www.omg.org/spec/CMMN/20151109/CMMNDI" xmlns:dc="http://www.omg.org/spec/CMMN/20151109/DC" xmlns:di="http://www.omg.org/spec/CMMN/20151109/DI" targetNamespace="http://www.flowable.org/casedef">
  <case id="my-case" name="my-case" flowable:initiatorVariableName="initiator">
    <casePlanModel id="casePlanModel" name="My Case" flowable:formFieldValidation="true">
      <planItem id="planItem1" name="preparation" definitionRef="sid-F67AD90C-5EDB-4746-A078-AA1E82339169" />
      <processTask id="sid-F67AD90C-5EDB-4746-A078-AA1E82339169" name="preparation" flowable:fallbackToDefaultTenant="false">
        <processRefExpression><![CDATA[preparation]]></processRefExpression>
      </processTask>
    </casePlanModel>
  </case>
</definitions>

The referenced BPMN workflow contains some UserTask.

When I launch an instance of the case, I manage to access the tasks created by the BPMN via the reference id of the PlanItemInstance as it is equals to the BPMN process id :

CaseInstance → PlanItemInstance – (reference id) -> ProcessInstance → Task

But when it comes to historical objects, the link between HistoricalPlanItemInstance and HistoricalProcessInstance is broken (reference id is null) so I can’t access the historical tasks created by the process instance.

Any idea how to workaround this issue ?

Thank you
Regards

That’s indeed a bug and has been discovered and fixed on master: flowable-engine/ProcessTaskTest.java at master · flowable/flowable-engine · GitHub

The only way to fix it, would be to change the HistoryManager with a custom implementation that executes the logic that is done here: Fix referenceId and referenceType not set on the HistoricPlanItemInst… · flowable/flowable-engine@a4302d8 · GitHub

Thank you for your reply.

Finally, I had to implement a workaround by keeping the reference in a local variable on completion:

taskService.setVariableLocal(task.getId(), "planItemInstanceId", planItemInstance.getId());

Regards