How to track the user completing the subtask(Check List Task) in the parent task?

cancel
Showing results for 
Search instead for 
Did you mean: 
paiyyavj13
Established Member II

How to track the user completing the subtask(Check List Task) in the parent task?

Jump to solution

Hi,

I have a Task belonging to a process, when this task is claimed I trigger multiple self assigning Tasks by code. 

For example, if user1 claims the task then a couple of pre-defined subtasks are assigned to the same user, in this case user1. Now this user1 can complete these sub tasks or decide to assign it to someone else who eventually completes it.

I need to track the user completing these subtasks within a  process variable in the Parent Task. Or suggest a better way of achieving this....

Please guide me... Thank you...

Regards.

1 Solution

Accepted Solutions
gdharley
Intermediate

Re: How to track the user completing the subtask(Check List Task) in the parent task?

Jump to solution

Let me restate the question.

1. Process A - Task A assigned to User 1

2. Task B created (programmatically - although the mechanism is not relevant) as a sub task of Task A

3. Task B is reassigned to User 2

4. User 2 completes Task B

You want the ID of User 2 to be saved in a process variable in Process A for use later.

If I have your scenario correct:

Add a task listener to the "complete" event of the dynamically created task using something like:ActivitiListener listener

        new ActivitiListener();
        listener.setEvent(eventName);
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
        listener.setInstance(myTaskListenerImpl);
        MyUserTask.getTaskListeners().add(listener);

The Listener class (myTaskListenerImpl) will have a DelegateTask input, this will have a parentTask defined from which you can retrieve the parent task, then the associated process instance. Once you have this, you can create an instance variable.

Hope this is enough to move you forward.

Greg

View solution in original post

6 Replies
jearles
Established Member II

Re: How to track the user completing the subtask(Check List Task) in the parent task?

Jump to solution

Paiyyavj13_,

I don't know what version of Activiti you're using, but hopefully it's one of the relatively new versions - you should be able to make use of the Event Dispatcher mechanism that's now standard in Activiti.

As you define the event handlers, you can choose whether it should act globally or on an individual process instance and can be mapped to a plethora of standard events (like 'TASK_COMPLETED') - which would allow you to track those completed tasks.

I'm not sure if this is exactly what you were hoping for, but it is a solution Smiley Happy

Hope this helps,

-JEarles

gdharley
Intermediate

Re: How to track the user completing the subtask(Check List Task) in the parent task?

Jump to solution

Let me restate the question.

1. Process A - Task A assigned to User 1

2. Task B created (programmatically - although the mechanism is not relevant) as a sub task of Task A

3. Task B is reassigned to User 2

4. User 2 completes Task B

You want the ID of User 2 to be saved in a process variable in Process A for use later.

If I have your scenario correct:

Add a task listener to the "complete" event of the dynamically created task using something like:ActivitiListener listener

        new ActivitiListener();
        listener.setEvent(eventName);
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
        listener.setInstance(myTaskListenerImpl);
        MyUserTask.getTaskListeners().add(listener);

The Listener class (myTaskListenerImpl) will have a DelegateTask input, this will have a parentTask defined from which you can retrieve the parent task, then the associated process instance. Once you have this, you can create an instance variable.

Hope this is enough to move you forward.

Greg

paiyyavj13
Established Member II

Re: How to track the user completing the subtask(Check List Task) in the parent task?

Jump to solution

Thank you Greg.... this is exactly what I wanted.... Thank you Jonathan Earles too... the link you sent put me in the right track...

Will try the steps and post back...

Regards.

paiyyavj13
Established Member II

Re: How to track the user completing the subtask(Check List Task) in the parent task?

Jump to solution

HiGreg Harley,

I tried the steps mentioned by you but there is a small difference in the way I create my subtasks: they are of Type: "org.activiti.engine.task.Task" and not "org.activiti.bpmn.model.UserTask".

Hence, I could not add my listener to my subtask(as there is no api to get TaskListeners and set it in org.activiti.engine.task.Task).

I thought of changing my subtasks into "org.activiti.bpmn.model.UserTask" Type, but I could not find api to set tenantId and parentTaskId on it.

Could you suggest some pointers.... Appreciate your help!

Thank you....

Regards.

gdharley
Intermediate

Re: How to track the user completing the subtask(Check List Task) in the parent task?

Jump to solution

Hi,

You're right. My solution is how you would do igt in a parseHandler (which is where I pulled my code from).

From what I can tell (looking at the API), we can't add listeners dynamically, they have to be added to the process model either when the process is modeled, or inside a parse handler.

So....you should still be able to add a TaskListener that is triggered on the "assignment" event.

This listener can still create your sub tasks using code like:

 // save task         Task newTask = taskService.newTask();         newTask.setParentTaskId(parentTask.getId());         newTask.setName("MySubTask");         taskService.saveTask(newTask);

Now, you should also be able to add an event listener to the process that is bound to the TASK_COMPLETE event.

The listener would get the execution id from the event and from this you should be able to create a historicTaskInstance query based on the executionId.

Once you have the task, look to see if there is a parent task, if so, set the process variable.

Something of a long way around, but it should get you there.

Be aware, events are processed asynchronously which is why you need to use a history query rather than a runtime query because you cant guarantee order.

paiyyavj13
Established Member II

Re: How to track the user completing the subtask(Check List Task) in the parent task?

Jump to solution

Thank you Greg... Smiley Happy