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?


Hey - Doesn’t this work - ?

Sample :
[{“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.

1 Like

I think we can fetch tasklist with taskVariables query parameter like -

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(
  • Make a list of task ids:
    val taskIdList = { }
  • 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”

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.