Can't retrieve historic variables from User Task of Multi Instance Subprocess


I’m using 7.11.0 and have a BPMN process with a multi instance subprocess which contains a user task that sets variables during completion via

taskService.complete(taskId, variables)

In a service task after the subprocess I’m trying to collect the variables of all these user tasks, but it looks like they are not historized?

historyService.createHistoricVariableInstanceQuery().taskIdIn(task.getId()).list().forEach(var -> log.debug("{} = {}", var.getName(), var.getValue()));

no result

historyService.createHistoricDetailQuery().taskId(task.getId()).list().forEach(var -> log.debug("{}", var));

no result

historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).list().forEach(var -> log.debug("{}", var));

2021-04-21 14:44:40.255 DEBUG 74815 — [aTaskExecutor-1] .ApproverGroupDecisionTaskManagementImpl : ----------------------------------------- HistoricTaskInstanceEntity[taskIdnull, assignee=1234567, owner=null, name=Systemrollen-genehmiger-entscheidung, description=null, dueDate=null, followUpDate=null, priority=50, parentTaskId=null, deleteReason=completed, taskDefinitionKey=approverGroupDecisionUserTask, durationInMillis=246, startTime=Wed Apr 21 14:44:39 CEST 2021, endTime=Wed Apr 21 14:44:39 CEST 2021, id=563f97b3-a29f-11eb-9ee5-9a55c5abc2a6, eventType=null, executionId=563e863f-a29f-11eb-9ee5-9a55c5abc2a6, processDefinitionId=idm-rolebuild:28:72399999-a29b-11eb-a749-ae8833d1b9b8, rootProcessInstanceId=55cd0030-a29f-11eb-9ee5-9a55c5abc2a6, processInstanceId=55cd0030-a29f-11eb-9ee5-9a55c5abc2a6, activityInstanceId=563e8640-a29f-11eb-9ee5-9a55c5abc2a6, tenantId=null]

P.S.: Sorry for the german screenshot, but I think the schema is understandable, the texts are not important, I think


Hi @Nabil,

maybe the variables are not in the scope of the task but rather in scope of the subprocess?

Hope this helps, Ingo

At first I thought, no, because I also tried

taskService.setVariables(taskId, variables);

instead of setting via complete().

But then I checked the docs again and found that:

Set variables on a task. If the variable is not already existing, it will be created in the most outer scope. This means the process instance in case this task is related to an execution.

I’ll try to find a way to initialize the variables at the task scope now.

Hi @Ingo_Richtsmeier,

I can’t find a way to set the variables at the task scope, only task local, but that won’t be historized (and I can’t change the history level of our camunda). All other setVariable methods seem to create the variable at the process scope, which is bad, because I’m using a multi instance subprocess and the many instances would overwrite the same process variable :-/

Can I initialize the variables at the task scope directly in xml/modeler? I tried input/output variables but they won’t end up in history variables either.


Hi @Nabil,

No, but you can initialize the variables in an execution listener as local variables. Then the form will reuse the local variables when the user completes the task.

Hope this helps, Ingo

As a workaround, I’m using task local variables now and a complete task listener on the user task that moves the local variables to the DelegateTask scope.