How to set output variables to Multi-Instance User task and to avoid common process variable overrides

Hii,

As per our project requirement we’re using the multi-instance user tasks.

  • Is there any workaround/solution to set the out put variables to multi-insstance tasks based on all instances response.
  • Also as per the documentation,

https://docs.camunda.org/manual/7.15/user-guide/process-engine/variables/#multi-instance-io-mapping

It mentioned that

No output mapping for multi-instance constructs

The engine does not support output mappings for multi-instance constructs. Every instance of the output mapping would overwrite the variables set by the previous instances and the final variable state would become hard to predict.

Is there any workaround to avoid this, and get all instances variables reponses to setup the Completion Condition

Thanks

There is a work around possible.
If you complete the task with localVariables in return instead of the standard global ones you can then add a task listener that can take those variables and add them with a java class or script to a global list. In this case i’ll be important to tick the Multi-instance Asynchronous Afterbox

Hello @Niall,

As per one scenario, i’m sending the below collection to the Multi-instance task

var userList = {
“ListOfUsers” :[
{“Name”:“user 1”, “approved”: false, “rejectReason”:"" },{“Name”:“user 2”, “approved”: false, “rejectReason”:"" }
]
}

and as per the User-task form i have the fields like rejectReason (textField) and approved (checkbox)
so each multi-instance user task form should input their resject reason values
as the process variables gets overrided in multi-instance task setup

i tried setting up the listeners to the User Task
Execution Listener (end script)
and task Listener also (complete event type)

and executing below javascript which updates the data in the userLIst collection process variable
But for some reason i think it’s only updating the data for the last instance only

var userList = execution.getVariable(‘UserList’);
var singleUser = execution.getVariable(‘singleUser’);
var rejectReason = execution.getVariable(‘rejectReason’);
var loopCounter = execution.getVariable(‘loopCounter’);
var confirmed = execution.getVariable(‘confirmed’);

if (loopCounter) {
var parsedUserList = JSON.parse(userList);
parsedUserList[“ListOfUsers”][loopCounter][“rejectReason”] = rejectReason;
parsedUserList[“ListOfUsers”][loopCounter][“approved”] = confirmed;
execution.setVariable(‘UserList’, JSON.stringify(parsedUserList));
execution.setVariable(‘UserList’, JSON.stringify(parsedUserList));
}

Is this existing camunda multi-task working that it executes the Listeners for the last instance only

Can you suggest any workaround for this issue i’m facing
i’ve attached the BPMN file for clear understanding

Expected Result:
As per the script added in listener it should update the collection data on each instance task completed

demo_order_multi_task_changes.bpmn (9.9 KB)

Thank You