cancel
Showing results for 
Search instead for 
Did you mean: 

/query/historic-task-instances retrieve wrong task variable data

aimingxu
Champ in-the-making
Champ in-the-making
When I create a process definition, I  used user task listener to set task variables to setup and track status and next status history required by client. I queried act_hi_varinst (select * from act_hi_varinst where proc_inst_id_='1627936' order by ID_) and found that info is correctly inserted as show below:
ID           INST_ID   EXEC_ID   TASK_ID   NAME    TYPE       TEXT
1627947   1627936   1627936   1627946   status    string          Assigned
1627948   1627936   1627936   1627946   nextStatus string       Pending Review
1627952   1627936   1627936   1627951   status    string        Pending Review
1627953   1627936   1627936   1627951   nextStatus string        Pending Close
1627958   1627936   1627936   1627957   status    string        Pending Close
1627959   1627936   1627936   1627957   nextStatus string        Closed

However,  when I query instance history with rest api /query/historic-task-instances, I got wrong history task variable info. As you can see, the task variables for different tasks are all the same as last task vraiables while they should be different as shown in act_hi_varinst table.

{
  "data": [
    {
      "id": "1627946",
     …
      "variables": [
        {
          "name": "nextStatus",
          "type": "string",
          "value": "Closed",
          "scope": "local"
        },
        {
          "name": "status",
          "type": "string",
          "value": "Pending Close",
          "scope": "local"
        }
      ]
    },
    {
      "id": "1627951",
     …
      "variables": [
        {
          "name": "nextStatus",
          "type": "string",
          "value": "Closed",
          "scope": "local"
        },
        {
          "name": "status",
          "type": "string",
          "value": "Pending Close",
          "scope": "local"
        }
      ]
    },
    {
      "id": "1627957",
     …
      "variables": [
        {
          "name": "nextStatus",
          "type": "string",
          "value": "Closed",
          "scope": "local"
        },
        {
          "name": "status",
          "type": "string",
          "value": "Pending Close",
          "scope": "local"
        }
      ]
    }
  ]
}

Is this a bug?

Thanks,
Aiming
4 REPLIES 4

jbarrez
Star Contributor
Star Contributor
Without knowing what your task listener does ..  this is hard to say. Does it set local vars? if so, it could return different variables …

aimingxu
Champ in-the-making
Champ in-the-making
Yes, the task listener for task create is set to add local variables. Query act_hi_varinst table directly give correct results but activiti rest api /query/historic-task-instances give incorrect results. That is why I think it is a bug of the rest api. Here is the listener implementation in the definition.
<activiti:taskListener event="create" class="org.activiti.engine.impl.bpmn.listener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[status="Assigned";
   nextStatus="Pending Review"; task.setVariableLocal("status", status); task.setVariableLocal("nextStatus", nextStatus);]]></activiti:string>
          </activiti:field>
          <activiti:field name="language">
            <activiti:string><![CDATA[groovy]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
Aiming

aimingxu
Champ in-the-making
Champ in-the-making
The issue happens with version 5.19. I can no longer reproduce this issue after we upgraded to version 5.21 recently.

jbarrez
Star Contributor
Star Contributor
I vaguely seem to remember that we did work in the area of local variables a couple of months ago indeed.
Glad to hear it's fixed!