Access custom extension elements with the BPMN Model API

Hi all,

i have the following issue:

I have created a modeler with bpmn.io. The reason was that at some points in the process the user wants to have configuration options. (This is done before the process is released) These options should be shown in a form. My idea was to model this form (like the generated Forms can be created). The questions is how can I access them with the BPMN Model API? Is it possible to create an own Class like the CamundaFormData and load them with the following method? Or do should I use a “normal” XML API?

extensionElements.getElementsQuery().filterByType(CamundaFormData.class).singleResult();

XML:

<bpmn:startEvent id="StartEvent_1">
          <bpmn:extensionElements>
            <ownElement:form>
              <ownElement:groupField id="GroupField_35ed3ia">
                <ownElement:formData>
                  <ownElement:formField id="FormField_2pgt0fl" />
                  <ownElement:formField id="FormField_1k3bc92" />
                  <ownElement:formField id="FormField_0mveg4n" />
                </ownElement:formData>
              </ownElement:groupField>
              <ownElement:groupField id="GroupField_334n1h5">
                <ownElement:formData>
                  <ownElement:formField id="FormField_3soavdb" />
                  <ownElement:formField id="FormField_3667s9o" />
                </ownElement:formData>
              </ownElement:groupField>
              <ownElement:groupField id="GroupField_2tqoglf">
                <ownElement:formData>
                  <ownElement:formField id="FormField_3fs39ps" />
                  <ownElement:formField id="FormField_2p3akjh" />
                </ownElement:formData>
              </ownElement:groupField>
            </ownElement:form>
        </bpmn:extensionElements>
</bpmn:startEvent>

Thanks!
Dominik

Solved it :slight_smile:

Did it like CamundaFormData and the CamundaFormDataImpl

Just had to Add them like it is done in the Bpmn Method doRegisterTypes

OwnFormImpl.registerType(Bpmn.INSTANCE.getBpmnModelBuilder());
OwnGroupFieldImpl.registerType(Bpmn.INSTANCE.getBpmnModelBuilder());

I’m glad you found the solution. For reference, we have a CMMN-based example for this here: https://github.com/camunda/camunda-bpm-examples/tree/master/cmmn-model-api/typed-custom-elements

1 Like

@thorben @dominikh is there an example of how to access custom extension elements from bpmn, Here is my BPMN XML file with custom namespace called cus, I want to access cutomerId and customerName from the extension elements in my listeners and HistoryEventHandler, at the same time I do not want to add them as extension properties because that probably would expose these values if someone downloads the model.

<?xml version="1.0" encoding="UTF-8"?>

<bpmn:definitions xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:bpmn=“http://www.omg.org/spec/BPMN/20100524/MODEL” xmlns:bpmndi=“http://www.omg.org/spec/BPMN/20100524/DI” xmlns:dc=“http://www.omg.org/spec/DD/20100524/DC” xmlns:camunda=“http://camunda.org/schema/1.0/bpmn” xmlns:di=“http://www.omg.org/spec/DD/20100524/DI” xmlns:cus=“http://customer.domain.com” id=“Definitions_1” targetNamespace=“http://bpmn.io/schema/bpmn” exporter=“Camunda Modeler” exporterVersion=“3.7.2”>
<bpmn:process id=“TestSingleUsertaskOlyExtensionElements” name=“TestSingleUsertaskOlyExtensionElements” isExecutable=“true” camunda:versionTag=“V1”>
bpmn:extensionElements
cus:customerIdcus-hrkf87pv9a</cus:customerId>
cus:customerNamecus-213232</cus:customerName>
</bpmn:extensionElements>
<bpmn:startEvent id=“StartEvent_1”>
bpmn:extensionElements
<camunda:executionListener class=“TestJava” event=“start” />
</bpmn:extensionElements>
bpmn:outgoingFlow_07exjn4</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id=“Flow_07exjn4” sourceRef=“StartEvent_1” targetRef=“TestHarishSingleTask” />
<bpmn:sequenceFlow id=“Flow_1kqqkrn” sourceRef=“TestHarishSingleTask” targetRef=“Event_0iun2ar” />
<bpmn:endEvent id=“Event_0iun2ar”>
bpmn:incomingFlow_1kqqkrn</bpmn:incoming>
</bpmn:endEvent>
<bpmn:userTask id=“TestHarishSingleTask” name=“TestHarishSingleTask”>
bpmn:incomingFlow_07exjn4</bpmn:incoming>
bpmn:outgoingFlow_1kqqkrn</bpmn:outgoing>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id=“BPMNDiagram_1”>
<bpmndi:BPMNPlane id=“BPMNPlane_1” bpmnElement=“TestSingleUsertaskOlyExtensionElements”>
<bpmndi:BPMNEdge id=“Flow_1kqqkrn_di” bpmnElement=“Flow_1kqqkrn”>
<di:waypoint x=“360” y=“120” />
<di:waypoint x=“516” y=“120” />
<di:waypoint x=“516” y=“130” />
<di:waypoint x=“672” y=“130” />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id=“Flow_07exjn4_di” bpmnElement=“Flow_07exjn4”>
<di:waypoint x=“209” y=“120” />
<di:waypoint x=“260” y=“120” />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id=“_BPMNShape_StartEvent_2” bpmnElement=“StartEvent_1”>
<dc:Bounds x=“173” y=“102” width=“36” height=“36” />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id=“Activity_09gmeyv_di” bpmnElement=“TestHarishSingleTask”>
<dc:Bounds x=“260” y=“80” width=“100” height=“80” />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id=“Event_0iun2ar_di” bpmnElement=“Event_0iun2ar”>
<dc:Bounds x=“672” y=“112” width=“36” height=“36” />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

Follow the same pattern as above, but you can use ExtensionElements (Camunda BPM Javadocs 7.14.20-ee) instead.

@StephenOTT thank you for the quick response, I think I am able to retrieve the extension elements when they are added as properties under extension tab either at process level or at task level, But not able to retrieve them when I do have my own custom namespace with extension elements within my namespace

Example :
as extension elements directly with my own cus namespace
bpmn:extensionElements
cus:idsr-4328n0qonq</cus:id>
cus:nameten-hrkf87pv9a</cus:name>
</bpmn:extensionElements>

instead of extension properties that uses camunda namespace

bpmn:extensionElements
camunda:properties
<camunda:property name=“cus:name” value=“tn-2132432sad” />
<camunda:property name=“cus:id” value=“sr-aasdsa2324” />
</camunda:properties>
</bpmn:extensionElements>