AnsweredAssumed Answered

How to attach boundary error event to a service task

Question asked by rgoel on Dec 4, 2014
Latest reply on Apr 18, 2016 by osganian
Hi,
   I have a requirement to attach boundary error event to a service task. This service task is part of the same process in which the error is thrown . I have seen examples in activiti source code where boundary error event is either attached to user task or to a subprocess.

Here is my bpmn xml file:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">

  <process id="POCAsyncProcessWith2AsyncAndErrorHandling" name="Example of usage of 2 Asynch process with error handling" isExecutable="true">
    <startEvent id="startevent1" name="Start">
      <extensionElements>
        <activiti:executionListener event="start" delegateExpression="${activitiStartWorkflowExecutionListener}"></activiti:executionListener>
      </extensionElements>
    </startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <serviceTask id="poc_task1" name="poc task1" activiti:delegateExpression="${activitiPOCTask1}"></serviceTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="poc_task1"></sequenceFlow>
    <serviceTask id="poc_task2" name="poc task2" activiti:async="true" activiti:delegateExpression="${activitiPOCTask2}"></serviceTask>
    <serviceTask id="poc_task3" name="poc task3" activiti:delegateExpression="${activitiPOCTask3}"></serviceTask>
    <sequenceFlow id="flow10" sourceRef="poc_task2" targetRef="poc_task3"></sequenceFlow>
    <serviceTask id="poc_task4" name="poc task4" activiti:async="true" activiti:delegateExpression="${activitiPOCTask4}"></serviceTask>
    <sequenceFlow id="flow11" sourceRef="poc_task3" targetRef="poc_task4"></sequenceFlow>
    <serviceTask id="poc_taskerror" name="poc error task" activiti:delegateExpression="${activitiPOCTaskError}"></serviceTask>
    <sequenceFlow id="flow12" sourceRef="poc_task1" targetRef="poc_taskerror"></sequenceFlow>
    <sequenceFlow id="flow13" sourceRef="poc_taskerror" targetRef="poc_task2"></sequenceFlow>
    <sequenceFlow id="flow14" sourceRef="poc_task4" targetRef="endevent1"></sequenceFlow>
    <serviceTask id="poc_task_error_handler" name="poc task error handler" activiti:delegateExpression="${activitiPOCTaskErrorHandler}"></serviceTask>
    <sequenceFlow id="flow16" sourceRef="poc_task_error_handler" targetRef="endevent1"></sequenceFlow>
    [H1]<boundaryEvent id="catchError" name="catchError" attachedToRef="poc_task1">[/H1]
      <errorEventDefinition errorRef="BusinessExceptionOccurred"></errorEventDefinition>
    </boundaryEvent>
    <sequenceFlow id="flow17" sourceRef="catchError" targetRef="poc_task_error_handler"></sequenceFlow>
    <textAnnotation id="versionNumber">
       <text>2.3</text>
    </textAnnotation>
  </process>

Here, if I  have attachedToRef="poc_taskerror", it works fine as poc_taskerror is the task which throws bpmn error and activiti is able to find all errorEventDefinitions in the scope. It then transfers flow to  poc_task_error_handler.

But when I have attachedToref to another service task , in the same process before the task which throws error, activiti is not able to figure out any  errorEventDefinitions  in the scope .

My question is " Can we attach boundary error events only to subprocess or usertask ?

Appreciate response.

regards,
rgoel

Outcomes