Hello,
I have a process like this:
The first task has a form with an input field called myVar. The user sets myVar to “yes” and finishes the task.
We are working with historics so if i query the ACT_HI_VARINST table I can see following records:
The second task has a similar form with the same input field. Now, the user sets myVar to “no” and finishes the task. The content of the ACT_HI_VARINST table is:
The third task has a form that shows myVar value. The user see myVar = “no” and completes the task without passing any value for myVar variable. The ACT_HI_VARINST table doesn’t change.
The problem comes when we get the task form model using taskService.getTaskFormModel method. We expect to see myVar=“no” but it’s value is “yes”.
Debugging the code, I see that when flowable is trying to load the variables’s HashMap in GetTaskFormModelCmd (from historic), first it is loading the task variables in map (no variables added because that form only had an expression field), and then it is loading the process variables.
The problem is that GetTaskFormModelCmd class execute this code (we are using flowable 6.8.0):
processEngineConfiguration.getHistoryService()
.createHistoricVariableInstanceQuery().taskId(taskId).list()
.stream()
.forEach(variableInstance -> variables.putIfAbsent(variableInstance.getVariableName(), variableInstance.getValue()));
processEngineConfiguration.getHistoryService()
.createHistoricVariableInstanceQuery().processInstanceId(task.getProcessInstanceId()).list()
.stream()
.forEach(variableInstance -> variables.putIfAbsent(variableInstance.getVariableName(), variableInstance.getValue()));
We see that the process variables are getting by HistoricVariableInstanceQuery, setting processInstanceId predicate. This query returns the 3 records sorted as i showed in the table avobe and the value that is added in HashMap is “yes” because of it is using putIfAbsent method (only first record is added).
Are we doing something wrong or is it a flowable bug?
We can solve the problem passing myVar = no, in that way the command would get myVar value form task variables (only one record) but we would like to know if we have to do that as general rule.
Thanks a lot.