Parent task completing without Sub task incomplete

127 views
Skip to first unread message

Jayendran Subramanian

unread,
Feb 6, 2015, 9:23:08 AM2/6/15
to camunda-...@googlegroups.com
Hi,

I created a runtime task as a child task. When the parent task is completed, sub task is also completed automatically even though it is still being acted upon. Is there any way we can put some condition that a parent task can not be completed until a child task is completed?

Regards
Jayendran

thorben....@camunda.com

unread,
Feb 6, 2015, 10:28:15 AM2/6/15
to camunda-...@googlegroups.com
Hi Jayendran,

You could use a task listener for the complete event of the parent task that throws an exception, when there are active sub tasks left. [1] shows a snippet for how to define a task listener in the BPMN XML. If you want this for a greater number of tasks, you can register the listener programmatically from a process engine plugin with a parse listener (see [2] for an example).

Best regards,
Thorben

[1] http://docs.camunda.org/latest/api-references/bpmn20/#tasks-user-task-user-assignment-using-custom-extensions
[2] https://github.com/camunda/camunda-bpm-examples/tree/master/process-engine-plugin/bpmn-parse-listener

Jayendran Subramanian

unread,
Feb 9, 2015, 2:01:24 AM2/9/15
to camunda-...@googlegroups.com
Hi Thorben,

I defined a  tasklistener for usertask(parent).In notify method how to get the active sub task of parent user task. In delegate task no such a method to get active sub tasks list to verify. Please advise.

Regards
Jayendran

thorben....@camunda.com

unread,
Feb 9, 2015, 3:56:35 AM2/9/15
to camunda-...@googlegroups.com
Hi Jayendran,

You can use something like this in your TaskListener:

TaskService taskService = delegateTask.getProcessEngineServices().getTaskService();
List<Task> subTasks = taskService.getSubTasks(delegateTask.getId());

Completed sub tasks should not appear in that list.

Cheers,
Thorben

Jayendran Subramanian

unread,
Feb 9, 2015, 4:44:33 AM2/9/15
to camunda-...@googlegroups.com
Hi Thorben, thanks for the details,

This works fine. On complete event fires tasklistener it list active sub task, if sub task active then how to stop completing parent task.

        ProcessEngineServices pes = delegateTask.getProcessEngineServices();
        TaskService ts = pes.getTaskService();
        List<Task> taskList =ts.getSubTasks(delegateTask.getId());
        if(!taskList.isEmpty()){
            for (Task task : taskList) {
                  if(!task.isSuspended()){
                      count++;
                      actFlag  = true;
                  }
             }
        }

Regards
Jayendran

thorben....@camunda.com

unread,
Feb 9, 2015, 4:54:15 AM2/9/15
to camunda-...@googlegroups.com
Hi Jayendra,

Just throw any uncaught exception. The process engine transaction will then be rolled back and the task completion aborts.

Some something like:

        ProcessEngineServices pes = delegateTask.
getProcessEngineServices();
        TaskService ts = pes.getTaskService();
        List<Task> taskList =ts.getSubTasks(delegateTask.getId());
        if(!taskList.isEmpty()){
            for (Task task : taskList) {
                  if(!task.isSuspended()){
                      throw new RuntimeException("Cannot complete task " + delegateTask.getId() + ". It has active sub tasks that need to be completed before.");
                  }
             }
        }

Cheers,
Thorben

Jayendran Subramanian

unread,
Feb 9, 2015, 5:48:53 AM2/9/15
to camunda-...@googlegroups.com
Thanks Thorben, This works fine as expected.
Reply all
Reply to author
Forward
0 new messages