# Creating dynamic tasks

**URL:** <https://forum.flowable.org/t/creating-dynamic-tasks/1396>\
**Category:** Flowable Engine\
**Created:** [January 5, 2018, 7:46am UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396 "2018-01-05T07:46:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [January 5, 2018, 7:46am UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/1 "2018-01-05T07:46:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [January 8, 2018, 4:31am UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/2 "2018-01-08T04:31:20Z")

</div>

Awaiting for a quick response please. Thanks.

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [January 8, 2018, 10:16am UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/3 "2018-01-08T10:16:11Z")

</div>

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](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](https://github.com/flowable/flowable-engine/pull/706)

Regards  
Martin

---

<div class="post-metadata">

**Author:** ![fegorama](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fegorama/32/313_2.png) [@fegorama](https://forum.flowable.org/u/fegorama)\
**Post date:** [January 8, 2018, 10:17am UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/4 "2018-01-08T10:17:06Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [January 8, 2018, 12:31pm UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/5 "2018-01-08T12:31:22Z")

</div>

Thank you so much for the reply.

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

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.

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [January 8, 2018, 1:07pm UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/6 "2018-01-08T13:07:48Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [January 10, 2018, 12:21pm UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/7 "2018-01-10T12:21:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [January 11, 2018, 4:02am UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/8 "2018-01-11T04:02:59Z")

</div>

Please help. Awaiting for a response.

Thanks

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [January 11, 2018, 6:42am UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/9 "2018-01-11T06:42:06Z")

</div>

> <https://github.com/flowable/flowable-engine/blob/ee4f943f49f9b05b7fcc4bae0e11a78efa5a07b9/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/task/SubTaskTest.java#L31>

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [January 11, 2018, 7:04am UTC](https://forum.flowable.org/t/creating-dynamic-tasks/1396/10 "2018-01-11T07:04:45Z")

</div>

Thank you so much. It worked
