Not able to update camunda process variables from execution listeners end script or Task listeners complete/delete scripts


im trying to update the process variables in the Execution listeners end script

As in Multi-instance task we cannot set the Output variables,
i setup the execution listener
in which i need to update one status process variable after all multi-instance tasks are completed

i used simple Javascript code to update the status variable,
same script code i tried with the task listeners end script

var nrOfInstances = execution.getVariable(‘nrOfInstances’);
var nrOfCompletedInstances = execution.getVariable(‘nrOfCompletedInstances’);
var nrOfActiveInstances = execution.getVariable(‘nrOfActiveInstances’);

if (nrOfActiveInstances == 0)
execution.setVariable(‘status’, “REVIEW_COMPLETED”);
execution.setVariable(‘status’, “HALF_REVIEW_COMPLETED”);

but as i noticed i’m not getting the updated values of the multi-instance varaibles
e.g. nrOfInstances, nrOfCompletedInstances, nrOfActiveInstances

i.e after one instance completed of all multi-instance, it should give me udpated
nrOfCompletedInstances count but it does not provide the updated count

is there any workaround or solution where i can set the final status process variable after all multi-instance instances are completed.

PFA for BPMN file
demo_order_multi_task_changes.bpmn (10.4 KB)

Thank You