How to get next User Task for a specific user?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2013 01:45 AM
When we design a BPMN process, we define the various activities to be performed by the user and system, in a specified SEQUENCE and a WELL DEFINED ORDER. We also define which USER TASK is assigned. Thereby the BPMN engine knows which User has what task Assigned and also in what order. Then why do we need to pass the Task Definition ID for fetching the user task in the following manner
Task tasks = processEngine.getTaskService().createTaskQuery().taskDefinitionKey("fof").list();
Why is it that we need to tell activiti ID of the task when it already has the process definition that defines tasks and its candidate users. Why cant we have something like this in activiti to fetch next task for the current user
Task tasks = processEngine.getTaskService().getNextTask(User currentUser);
I know there is processEngine.getTaskService().createTaskQuery().taskAssignee(), but is returns all the tasks that are assigned to a specific user and not the next task for the user.
Please suggest what should be done.
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2013 05:37 AM
I know there is processEngine.getTaskService().createTaskQuery().taskAssignee(), but is returns all the tasks that are assigned to a specific user and not the next task for the user.
I don't really understand what you mean with 'next task'.
Is it a task that doesn't exist yet because the process instance hasn't arrived yet there?
Is it a task that does exist, but is not yet claimed (ie only candidate user/group and nobody has claimed it yet) ?
Or is it something else?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2013 01:50 PM
1. START PROCESS
2. USER TASK-A
[taskDefinitionKey : TA, assignee : "JOHN", description : enter EmpID and timesheet]
3. SERVICE TASK-1
[description : Compute Salary]
4. USER TASK-B
[taskDefinitionKey : TB, assignee : "JOHN", description : submit Medical Bills for reimbursment]
5. USER TASK-C
[taskDefinitionKey : TC, assignee : "LISA", description : approve Medical bills ]
6. END PROCESS
Now in the above process both the User Task have been pre-assigned to user JOHN and LISA resp. but in order to access these task programmatically at any point in the code we need to write the following code to access the task
List<Task> tasks = processEngine.getTaskService().createTaskQuery().taskDefinitionKey("TA").list();
why do we need to pass TaskDefinitionKey in order to fetch the task object. In that case the client code interacting with the activity engine MUST always know the all the taskDefinitionIDs to fetch any of the task in order to complete the task. which does not seem to be a very good idea. Rather the client code should only know about current user data like the "assigneeName". So once the process starts the current process is at TASK-A, which is assigned to JOHN and in order to access the above task for completion the client Code (may be a Spring MVC Controller or a Struts Action) does not need to know the taskDefinitionID i.e. TA, rather just passing the assignee name i.e. "JOHN" to the engine the client code should be able to retrieve the TASK-A. and similarly for the other TASK.
In case the Task has been assigned to a specific group rather than a user, still a user should be able to access the TASK by passing username in case the use is a candidate of the assigned group.
I hope this explains my doubt.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2013 07:53 AM
Second - how would this work for assignements defined using expressions? How do you want the engine to evaluate an expression defined on the "next" task, if this task doesn't even exist yet? Please remember that you are "preassigning" a task on a definition level. When you deploy the BPMN definition - none of the tasks aren't created and their preassignements are unknown to the engine.
Third - if you REALLY, REALLY want to implement this bad idea (in my opinion of course), I think you should handle it during BPMN parse (using BpmnParseHandler or BpmnParseListener). You could then try to follow the sequence flow after each task.
Best regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2013 04:22 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2013 07:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2013 01:12 PM
why do we need to pass TaskDefinitionKey in order to fetch the task object
You don't. Have a closer look at the taskquery api. You can query by assignee to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2017 05:15 AM
Yes you are right,but to query by assignee first we need to set the assignee. I am stuck here itself,suppose two user task with two different assignee.On starting the process i get access to only first user task because for activiti engine the 2nd user task doesn't exist still.But i want to pre-assign the assignee to all user tasks and start the process flow,querying by assignee.
