cancel
Showing results for 
Search instead for 
Did you mean: 

query/tasks in activiti rest api not giving desired results

vickysirwani
Champ in-the-making
Champ in-the-making
I have attached a bpmn file and the two files being used in Java Service Tasks.
I start the process and set the form property f1 to asd.
Then I hit the query/tasks rest api with the following body:
{
    "assignee": "kermit",
    "taskDefinitionKey": "ut2",
    "processInstanceVariables": [
         {
      "name": "questionnaire",
      "type": "string",
      "value": "asd",
        "operation":"equals"
      }   
     ]

}

I get the following result:
{
    "data": [
        {
            "id": "25093",
            "url": "http://xxxxxx/service/runtime/tasks/25093",
            "owner": null,
            "assignee": "kermit",
            "delegationState": null,
            "name": "UT2",
            "description": null,
            "createTime": "2014-07-27T17:17:36.257+0000",
            "dueDate": null,
            "priority": 50,
            "suspended": false,
            "taskDefinitionKey": "ut2",
            "tenantId": "",
            "category": null,
            "parentTaskId": null,
            "parentTaskUrl": null,
            "executionId": "25085",
            "executionUrl": "http://xxxxxx/service/runtime/executions/25085",
            "processInstanceId": "25068",
            "processInstanceUrl": "http://xxxxxx/service/runtime/process-instances/25068",
            "processDefinitionId": "myProcess:1:25067",
            "processDefinitionUrl": "http://xxxxxx/service/repository/process-definitions/myProcess%3A1%3A25067",
            "variables": []
        },
        {
            "id": "25098",
            "url": "http://xxxxxx/service/runtime/tasks/25098",
            "owner": null,
            "assignee": "kermit",
            "delegationState": null,
            "name": "UT2",
            "description": null,
            "createTime": "2014-07-27T17:17:36.259+0000",
            "dueDate": null,
            "priority": 50,
            "suspended": false,
            "taskDefinitionKey": "ut2",
            "tenantId": "",
            "category": null,
            "parentTaskId": null,
            "parentTaskUrl": null,
            "executionId": "25087",
            "executionUrl": "http://xxxxxx/service/runtime/executions/25087",
            "processInstanceId": "25068",
            "processInstanceUrl": "http://xxxxxx/service/runtime/process-instances/25068",
            "processDefinitionId": "myProcess:1:25067",
            "processDefinitionUrl": "http://xxxxxx/service/repository/process-definitions/myProcess%3A1%3A25067",
            "variables": []
        },
        {
            "id": "25103",
            "url": "http://xxxxxx/service/runtime/tasks/25103",
            "owner": null,
            "assignee": "kermit",
            "delegationState": null,
            "name": "UT2",
            "description": null,
            "createTime": "2014-07-27T17:17:36.262+0000",
            "dueDate": null,
            "priority": 50,
            "suspended": false,
            "taskDefinitionKey": "ut2",
            "tenantId": "",
            "category": null,
            "parentTaskId": null,
            "parentTaskUrl": null,
            "executionId": "25089",
            "executionUrl": "http://xxxxxx/service/runtime/executions/25089",
            "processInstanceId": "25068",
            "processInstanceUrl": "http://xxxxxx/service/runtime/process-instances/25068",
            "processDefinitionId": "myProcess:1:25067",
            "processDefinitionUrl": "http://xxxxxx/service/repository/process-definitions/myProcess%3A1%3A25067",
            "variables": []
        }
    ],
    "total": 3,
    "start": 0,
    "sort": "id",
    "order": "asc",
    "size": 3
}

I believe I should be getting only 1 result as I am setting the variable questionnaire as "asd" only once.

But here I am getting 3 results with taskIds: 25093, 25098 and 25103.

When I query variables of taskId 25093, I get the expected result:

[
{
name: "questionnaire",
type: "string",
value: "asd",
scope: "global"
},
{
name: "nrOfInstances",
type: "integer",
value: 3,
scope: "global"
},
{
name: "questionaireCollection",
type: "serializable",
value: null,
valueUrl: "http://xxxxxxxx/service/runtime/tasks/25093/variables/questionaireCollection/data",
scope: "global"
},
{
name: "nrOfActiveInstances",
type: "integer",
value: 3,
scope: "global"
},
{
name: "f1",
type: "string",
value: "asd",
scope: "global"
},
{
name: "nrOfCompletedInstances",
type: "integer",
value: 0,
scope: "global"
},
{
name: "loopCounter",
type: "integer",
value: 0,
scope: "global"
}
]

Also, when I query the tasks for the taskId 25098, I get expected result, the variable questionnaire set to "qwe".

Am I missing something?

Is this the expected result for query/tasks?
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
it seems like all 3 tasks are part of the same process-instance. You're actually requesting all tasks that are part of a process-instance which have a variable with name 'questionnaire' set to a certain value. You're querying based on process-variables, not on task-local variables - makes sense you get 3 results if all those 3 tasks are part of such a process…