Add a new task in multi-instance tasks

Hi,

I have been trying to implement this feature but couldn’t find a solution. Need help

I have created a multi-instance task and based on loop cardinality, ‘n’ number of task are generated and assigned to those users. Now these ‘n’ users can add other users to this stage and until all ‘n’ users and users who were added later during the stage finish the task, the workflow should not move to next stage.

I am creating a new task but that task is not part of the multi-instance process and so when all task of multi-instance process is completed ‘ACT_RU_TASK’ has next stage pending task. The task that I create is still pending in ACT_RU_TASK and both stages get active.

Please help.

Awaiting for response…

Hi Amitshukla,

Adding tasks dynamically to the process is allowed, but in your case you want to add new tasks into the multiinstance task. You have to adjust loop variables and executions involved in the loop (especially in the case of parallel multiinstance task). To do that I would create special command which can be executued by management service.

In the case of sequential multiinstance task, have a look on
org.flowable.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior#leave
method. If you set all loop internal variables properly, your newly added items should be added properly.

In the case of parallel multiinstance task,
org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior#createInstances
creates all instances before the loop start. The case is little bit more complicated than the sequential. I would add new executions and tasks with the loop variables and according these changes parent loop variables need to be changed too.

Regards
Martin

1 Like