Get task list with variables

Hi all.

We are creating an app (HTML/Javascript) to list user tasks. The app shows some task fields, like name or dates. We also want to display some variables in that list. The app gets the task list via Rest API filtered by some fields.

Is there a way to fetch a task list with its own variables via Rest or JAVA API?

Thanks.

Hey - Doesn’t this work - https://docs.camunda.org/manual/7.11/reference/rest/task/post-query/ ?

Sample :
{
“processVariables”:
[{“name”: “amount”,
“value”: “900”,
“operator”: “eq”
}]
}

Nope, that will search for tasks which have the “amount” variable with value “900”.

The question is: Is there any way to search for tasks and get them with their variables in the same response?

At the moment, to get that response, we need to make the search and then, for each task, get their variables, resulting in lots of requests.

@pmanu93 at present you have to make two api calls to get the variables, one is for fetching tasklist and another call is for fetching variables for those tasks.

If you are interested in fetching tasks and variables in one call, then you can write a native query to fetch in one api call.

https://docs.camunda.org/manual/7.11/user-guide/process-engine/process-engine-api/#native-queries

https://docs.camunda.org/manual/7.6/examples/tutorials/custom-queries/#custom-mybatis-queries

1 Like

I think we can fetch tasklist with taskVariables query parameter like -
/task?taskVariables=state_eq_ASSIGNED

this will filter the tasks for given query parameters and it won’t return the response with variables.

You mentioned two api calls.

  1. Get list of tasks - for example GET `/task?assignee=anAssignee'
  2. What is the second?

We can get variables of particular task via GET /task/{id}/localVariables
But can we get variables of a task list via one api call?

1 Like

Resolved this problem in this way:

  • Create new rest controller on the back.
  • This rest controller gets the list of tasks for current user:
    val taskList: List<Task> = taskService.createTaskQuery().taskAssignee(principal.id).list()
  • Make a list of task ids:
    val taskIdList = taskList.map { it.id }
  • Get a list of variables for there task ids with concrete name (taskDetails)
    val varList = runtimeService.createVariableInstanceQuery() .taskIdIn(*taskIdList.toTypedArray()).variableName("someVariableName").list()
  • Write variable values to corresponding task instances - to variable “description”
4 Likes

I find it odd that such a solution is required given that Activiti’s api (5.21.0) allows one simply return tasks and variables together with
List<Task> tasks = query.includeProcessVariables().list();

I had thought Camunda forked from Activiti after 5.21.0, which would indicate this functionality was deliberately removed. I have to wonder why. There’s nothing wrong with your workaround, I just wonder why it’s necessary.

1 Like

As I can see includeProcessVariables is used for ProcessInstanceQuery, but I needed to query tasks, not process instances.