Customised elements removed when model loaded

I have been following the examples for adding custom elements, which has been a partial success.

This is working fine for when I update the diagram and save the XML, I see the custom elements in there. However when I attempt to load the same XML in to the modeler, the custom elements have been taken out.

Could there be an obvious reason for that? Such as something I need to ensure is in my customisation file? Only I think I’ve followed the examples, so I would expect this to work?

As an example, I’m trying to allow this XML to be created:

<bpmn:timerEventDefinition id="TimerEventDefinition_14abtv0">
       <bpmn2:timeCycle cron="0/1 * * * * ?" />
</bpmn:timerEventDefinition>

which I have been able to do and to save the resultant XML. However when loading the XML model in to the modeler, this element has reverted back to:

<bpmn:timerEventDefinition id="TimerEventDefinition_14abtv0" />

So is there something that I need to define for the bpmn2 namespace or the bpmn2:timeCycle element for the modeler to be allow such elements to also be loaded as well as saved?

Can you maybe share your project as a CodeSandbox? It will help us a lot to review your configurations and custom modules, and then expect what’s going on.

I’ve created this sandbox which is a recreation of the problem I’m having - https://codesandbox.io/s/loving-sun-xrvge?file=/src/index.js

In there you can see the XML that is being loaded in which contains customised elements such as:

<bpmn2:property>
<bpmn2:timeCycle>
<bpmn2:conditionExpression>

This is loaded in using importXML and when the “Save” button (top left) is clicked then saveXML is called and within that the XML to be saved is written to the console where it can be seen that the above custom elements are no longer in the XML.

Any help is appreciated.

Hi. Can anyone help me with this issue? Apologies if it’s basic or missing the point. But nonetheless I could still do with some help with what to do …! Many thanks.

These elements are removed because they are considered extensions and thus are not allowed in the places where there are in the original XML. property, timeCycle and conditionExpression are already defined in the BPMN model, why redefine them in a bpmn2 extension?

Is it that you want to customize these elements? If so, customize them by adding extension elements that are defined in an extension. Here’s an example: https://github.com/bpmn-io/bpmn-js-example-model-extension

Thanks for that. And I agree, if these elements are already part of the BPMN model then there is indeed no need to re-define them.

However, when I attempt to execute the following (in my app code or in the sandbox https://codesandbox.io/s/loving-sun-xrvge?file=/src/index.js):

const bpmnFactory = bpmnJS.get("bpmnFactory");
bpmnFactory.create("bpmn:TimeCycle");

I get this error in the console:

Error: unknown type <bpmn:TimeCycle>

And I’ve tried using bpmn:timeCycle too and I get the same error. Am I missing something to allow this element to be recognised?

That won’t work. The type of the timeCycle property is actually bpmn:Expression. So you’d do:

const expression = bpmnFactory.create('bpmn:Expression');

eventDefinition.timeCycle = expression;

expression.$parent = eventDefinition;

You can find all the relevant information in the definition of the BPMN model of bpmn-js: https://github.com/bpmn-io/bpmn-moddle/blob/master/resources/bpmn/json/bpmn.json

1 Like