How to get completed task variables using REST API

I have been looking into history/detail API but I can’t seem to find a way to reconstruct completed task together with associated variables.

Any hint? TIA.

Hi, it depends on how you want to reconstruct it. If you merely want the variables associated with a task you can use https://docs.camunda.org/manual/7.12/reference/rest/history/variable-instance/get-variable-instance-query/ REST API using taskIdIn parameter.

Joe

Might be unrelated follow-up, but I learned later that the reason why I’m not getting the variables was because they’re not actually local task variables, but rather process variables. I verified that I can get the variable as I expected if I set them using API task/{id}/localVariables. But I couldn’t figure out how to do it from BPMN model.

For example, I tried from groovy script “task.setVariable” using task listener create, but it still doesn’t create local variable.

How can I create local task variable from my BPMN model?

Thanks in adavance.

execution.setVariableLocal("","")

I tried that in execution listener start, but still doesn’t seem to create local task variable.

I can almost vouch task.setVariableLocal("", “”) used to work, but now it seems I need to get executionId in my groovy script.

Have a look at this example localvariable.bpmn (2.6 KB) It sets local variables in both a Task and Execution Listener

task.setVariableLocal("taskListenerLocalVariable","taskListener")

execution.setVariableLocal("executionListenerLocalVariable","executionListener")

Right, so as you can see from the scopes, if you want to create a variable that is local to the task, create it in the task listener it seems