cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a task within a task

shikarishambu
Champ in-the-making
Champ in-the-making
I have a scenario where an user who is working on a task creates another task for a different person. Both these users can work on their tasks in parallel and they can complete in whatever order

What is the best way to handle this. Some questions I have are

1. Should the second task be treated as a subtask / same workflow
2. Should the second task be a task for user 1 but delegated to user 2
3. Should the second task be part of a different workflow (ideally, I would like to keep them in same workflow).

thanks
9 REPLIES 9

jbarrez
Star Contributor
Star Contributor
1. would be the way I would choose. If they can be completed in whatever order you probably keep it as flexible as possible.

Thanks. I am now running into a different issue related to creating the second task as a subtask of the first. I need to list all tasks including subtasks under a process instance. It looks like the subtask is not associated to the process instance. And, I need to get all tasks first and then query each one for its subtasks. Is there a way to do this without having the query every task for its subtasks.

I did come across this old post - not sure if there is a ticket - http://forums.activiti.org/content/java-api-get-tasks-and-subtasks-processinstanceid. I will be happy to create one. Unfortunately the link from activity.org to the JIRA takes me here - https://www.codehaus.org/termination/#tocAnchor-1-3


Thanks

jbarrez
Star Contributor
Star Contributor
> It looks like the subtask is not associated to the process instance.

You can always set the process instance id on the newly created task.


Jira has moved to https://activiti.atlassian.net/secure/Dashboard.jspa

Hi,
   >You can always set the process instance id on the newly created task.

I am not sure how to set the process instance id explicitly on a newly created task. I don't see a setter for ProcessInstanceId on the task object

http://activiti.org/javadocs/org/activiti/engine/task/Task.html

shikarishambu
Champ in-the-making
Champ in-the-making
Is the way to set the Process instance id by casting it to TaskEntity? Also, how would I retrieve all tasks (including completed ones) for a process instance. It looks like the HistoryService/ HistoricTaskInstanceQuery doesn't have anything that returns tasks by Process Instance Id. Or, should I go the route of Task Service - taskService.createTaskQuery().processInstanceId(processInstanceId).list(); BTW, why is there a significant performance difference between using Task Service and History Service (faster) for same/similar operations

trademak
Star Contributor
Star Contributor
Yes, you need to cast to TaskEntity. HistoricTaskInstanceQuery has a processInstanceId method (it extends from TaskInfoQuery). Can you share your results of the performance difference?

Best regards,

shikarishambu
Champ in-the-making
Champ in-the-making
Hi,
Here are results from our testing

|Scenario | 5 Parent Tasks Each with 5 SubTasks | 5 Parent Tasks Each with  2 SubTasks| 5 parents, 2 parent Task  with 5 SubTasks | 5parents, 2 parent task with 2 SubTasks|
|Only parent Task with TaskService |  281ms | 78ms | 110ms | 63ms |
|Including subTasks with TaskService | 765ms |508ms |436ms |345ms|
|Only parent Task with HistoryService | 47ms |180ms |47ms |33ms|
|Including subTasks with HistoryService|  566ms |546ms |703ms |799ms|

Hopefully, the formatting is ok.

I would be interested in learning what is the recommend/best way of accessing - all tasks/subtasks (associated to same process instance id) - both active and completed ones.

Thanks

trademak
Star Contributor
Star Contributor
Hi,

Thanks for sharing. Which db are you testing with?
I think the difference with retrieving the task via the task service could be that it will also load the identity links and some other data together with the task.

Best regards,

SQL Server 2008 R2 running on Windows 2008 server