The proper way of adding custom elements (superClass Element vs. bpmn:Task)

Hey everyone,

although this question might seems to be repetitive, I could not find an answer for our problem yet. In this post, I shared some details on our use case. What we do is creating workflows of different elements with each having a variety of parameters. Moreover, we have several sub elements that again take these elements to be the superClass of it.

For the moment, each custom element has the superClass of the bpmn:ServiceTask. When we add this moddleExtension to the BpmnModeler using for instance the key custom, our elements are represented in the XML format the following way (which works quite well):

<bpmn2:startEvent id="StartEvent_1" name="StartEvent">
  <bpmn2:outgoing>SequenceFlow_0k0bmor</bpmn2:outgoing>
</bpmn2:startEvent>
<custom:myCustomElement id="MyCustomElement_1ty1max" customParameter="abc">
  <bpmn2:incoming>SequenceFlow_0k0bmor</bpmn2:incoming>
  ...
</custom:myCustomElement>

However, I wonder, if this is the proper way to implement this modeling extension. While I found this answer from @nikku at Github, saying that making elements a sub-class of bpmn:Task is a valid option, I also read about bpmn:ExtensionElements on https://github.com/bpmn-io/bpmn-js-example-model-extension:

A few things are worth noting here:

You can extend existing types using the "extends" property.
If you want to add extension elements to bpmn:ExtensionElements they have to have "superClass": [ "Element" ].

I also found this answer from @philippfromme that lists the trade-offs of our solution. Now, I wonder, if our elements should not make use of the bpmn:ExtensionElements, too? In order to result in something like:

<bpmn2:startEvent id="StartEvent_1" name="StartEvent">
  <bpmn2:outgoing>SequenceFlow_0k0bmor</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:extensionElements>
  <custom:myCustomElement id="MyCustomElement_1ty1max" customParameter="abc">
    <bpmn2:incoming>SequenceFlow_0k0bmor</bpmn2:incoming>
    ...
  </custom:myCustomElement>
</bpmn2:extensionElements>

However, this is also the part, where I got stuck after checking out the example project GitHub - bpmn-io/bpmn-js-example-model-extension: An example of creating a model extension for bpmn-js and read some issues such as regarding extends and superClass.

I am really curious whether this structure a few lines above is even possible to create or whether it would instead look like the following:

<bpmn2:startEvent id="StartEvent_1" name="StartEvent">
  <bpmn2:outgoing>SequenceFlow_0k0bmor</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:serviceTask id="ServiceTask_XYZ">
  <bpmn2:incoming>SequenceFlow_0k0bmor</bpmn2:incoming>
  ...
  <bpmn2:extensionElements>
    <custom:myCustomElement id="MyCustomElement_1ty1max" customParameter="abc" />
  </bpmn2:extensionElements>
</bpmn2:serviceTask>

Maybe you can provide us some hints on when to use the solution of "superClass": ["bpmn:ServiceTask"] and when to use "superClass": ["Element"]? This would be really helpful.

As always, I am thankful for every hint. Additionally, thank you very much for your time and effort you are putting in this project and its support.

1 Like

The first snippet

<bpmn2:startEvent id="StartEvent_1" name="StartEvent">
  <bpmn2:outgoing>SequenceFlow_0k0bmor</bpmn2:outgoing>
</bpmn2:startEvent>
<custom:myCustomElement id="MyCustomElement_1ty1max" customParameter="abc">
  <bpmn2:incoming>SequenceFlow_0k0bmor</bpmn2:incoming>
  ...
</custom:myCustomElement>

is not valid BPMN 2.0 XML. I’m not entirely sure if the second snippet

<bpmn2:startEvent id="StartEvent_1" name="StartEvent">
  <bpmn2:outgoing>SequenceFlow_0k0bmor</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:extensionElements>
  <custom:myCustomElement id="MyCustomElement_1ty1max" customParameter="abc">
    <bpmn2:incoming>SequenceFlow_0k0bmor</bpmn2:incoming>
    ...
  </custom:myCustomElement>
</bpmn2:extensionElements>

would be valid but I’d strongly advise against trying to re-use BPMN elements within your custom extension.

Regarding the question of whether or not to use a BPMN flow node as the superclass of your custom element, it depends on how you want to add your extension.

Use a flow node (eg. bpmn:Task) to add attributes:

<bpmn2:task id="Task_1" name="Examine Situation" qa:suitable="0.7">

Use Element to add extension elements:

<bpmn2:extensionElements>
  <qa:analysisDetails lastChecked="2015-01-20" nextCheck="2015-07-15">
    <qa:comment author="Klaus">
      Our operators always have a hard time to figure out, what they need to do here.
    </qa:comment>
    <qa:comment author="Walter">
      I believe this can be split up in a number of activities and partly automated.
    </qa:comment>
  </qa:analysisDetails>
</bpmn2:extensionElements>

Note, that qa:AnalysisDetails must have Element as a superclass because only instances of Element are allowed in bpmn:ExtensionElements. qa:Comment does not have to have Element as a superclass.

All of this is demonstrated in the example: GitHub - bpmn-io/bpmn-js-example-model-extension: An example of creating a model extension for bpmn-js

Hope this helps. :+1:

2 Likes

Thank you so much for your detailed answer. This helps a lot!

1 Like