Hi, I have a requirement where I want to add a new assignee to an active multiuser task.
Suppose, below is the definition of the task :
< userTask id=“myTask” name=“my task” flowable:assignee="${parallelContributor}">
< multiInstanceLoopCharacteristics isSequential=“true” flowable:collection=“parallelContributors” flowable:elementVariable=“parallelContributor”>
< /userTask>
while launching, “parallelContributors” variable was initialized with “user1”," user2".
Now after task is initiated, I want add one more user to this task. I am trying to do this using following code:
List<String> userList = new ArrayList<String>();
userList.add("user1");
userList.add("user2");
userList.add("user3");
Map<String, Object> newUserListVariables = new HashMap<String, Object>();
variables.put("parallelContributors", userList);
List executions = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).list();
for (Execution execution : executions) {
if (execution instanceof ExecutionEntity) {
ExecutionEntity executionEntity = (ExecutionEntity) execution;
if (executionEntity.isMultiInstanceRoot()) {
runtimeService.setVariables(execution.getId(), newUserListVariables);
int nrOfInstances = (Integer) (runtimeService.getVariable(execution.getId(), “nrOfInstances”));
runtimeService.setVariable(execution.getId(), “nrOfInstances”, userList.size());
Here, using setVariables method I updated the collection and then incremented “nrOfInstances” variable to match the latest count of users.
This is working for sequential type of task. But for parallel type of task, the execution for new user3 does not get initiated.
My question is, is this the correct way to add contributor, or is there some other way to add new contributor.
I am on version 6.3.1 of flowable.