Creating dynamic tasks

Hi,

I have integrated flowable into my current project and everything’s working great. Now I am stuck into creating tasks dynamically.

So the requirement is user submits the request and it goes to head of the department. The head will choose which are the impacted units(departments) for this request. There could be n impacted units. The number of units he chooses is impacted by this request and submits, a parallel task will be created for all those corresponding unit heads and unit heads will work in parallel to get their task completed. Also when task assigned to impacted unit head, even he can add more impacted units and task will be created for that impacted unit head as well.

Please suggest me a nice way how do I design workflow and create parallel set of tasks dynamically depending on head chooses impacted units.

Awaiting for a response.
Thanks in advance.

amit

Awaiting for a quick response please. Thanks.

Hi Amit,

In the case when the process is stable I would suggest to:

Create list of “impacted units(departments)” and use multiinstance user task to itterate through the list and create tasks (http://www.flowable.org/docs/userguide/index.html#bpmnMultiInstance).

In the case of ad-hoc process, I would create a case for a user request and add tasks to this case. AdHoc case tasks implementation is https://github.com/flowable/flowable-engine/pull/706

Regards
Martin

1 Like

Hi!

You do create a task and adding in yout process instance:

Task t = taskService.newTask(“new task”);
List listTasks = taskService.createTaskQuery().list();
[…]
listTasks.add(t);

Thank you so much for the reply.

I have created a multiinstance user task. The tasks are getting created for n users but the value of assignee in table ACT_RU_TASK is null.

List<String> impactedUnitHead = new ArrayList<>();
impactedUnitHead.add("jason");
impactedUnitHead.add("sharon");
impactedUnitHead.add("roger");
variables.put("usersCount", 3);
variables.put("impactedUnitHead", impactedUnitHead);

In the flowable designer properties panel, I have set

Loop Cardinality -> 3
Collection -> ${impactedUnitHead}

So 3 tasks got created in table ACT_RU_TASK but assignees were null. I expected jason, sharon and roger to be the assignees of those tasks.

There are two other properties as well for Multi Instance tab

1. Element variable
2. Completion condition

Please guide me through this.

Awaiting for you response. Thanks in advance.

Amit,

check https://github.com/flowable/flowable-engine/blob/ee4f943f49f9b05b7fcc4bae0e11a78efa5a07b9/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/multiinstance/MultiInstanceTest.java#L261
you can find answers in the jUnit test.

Regards
Martin

2 Likes

Thank you very much for your solution. Now just one point that I am wondering how can I work that out. I am being able to create n tasks dynamically but once these tasks get assigned to respective users, even they can create tasks for other users. I tried to create new task

Task gonzoTask = taskService.newTask();
gonzoTask.setName("gonzoTask");
gonzoTask.setAssignee(assignee);
taskService.saveTask(gonzoTask);

This does create new task but without process instance id and lot of fields null. This task is not a subtask of the multiinstance dynamic n task created above. Infact it is parallel task to the multiinstance dynamic tasks. User forgot to create tasks for these at one go so the parallel multiinstance tasks assignees can add new task parallel to them.

Please help me in this. Awaiting for your quick response.

Thank you so much for your guidance.

Please help. Awaiting for a response.

Thanks

1 Like

Thank you so much. It worked