Add "ErrorBoundaryEvent" to the specific task

I have a case when I need to attach the boundary event (error boundary event especially) to the service task programmatically.
I.e. I need to attach it to the service task and refer it to some “bpmn:Error” element.

So, the “bpmn:Error” element should be created as well…
I’ve tried to find some info bout it, but no luck.

So, my question is: How to create the “bpmn:Error” element, the error boundary event that refers to the “bpmn:Error” element, and attach it to the “bpmn:ServiceTask”?
Are there any docs or suggestions about it?

Hi @Victor and welcome to the forum :slight_smile:

You will need to create a bpmn:boundaryEvent which containts a bpmn:errorEventDefinition.

So like this:

    <bpmn:boundaryEvent id="Event_1v5agwe" attachedToRef="Activity_1gt8qzi">
      <bpmn:errorEventDefinition id="ErrorEventDefinition_10y2zt8" />

In order to do this programatically, you should be able to do something like this:

const errorBoundaryEvent = elementFactory.createShape({
  type: 'bpmn:BoundaryEvent',
  eventDefinitionType: 'bpmn:ErrorEventDefinition'

The BoundaryEvent you will need to attach then to the respective task.

Please refer to this example:, in particular the Creating Shapes-snippet. I think this includes everything you need.