How to deep clone the extenstion elements of a notation

how to deep clone the extension elements of a notation ?
is there any method available for this?

What’s the context? Do you want to copy extension elements when copying and pasting elements?

Thanks for your time in advance.

I’m working on Undo/ Redo feature.
Here is my extension element.
Whenever I modify child property (ex: child:property) inside parent property, extension elements are getting updated properly. I can see the updated values in the xml generated.

However, when triggering an undo/redo action, we are not seeing the previous/old values for a given child property.

Steps to replicate:

  • Add some extension elements to any notation. Ex: start.
  • Get the child:property inside the parent:properties.
  • Update the property with a new value (ex: update ‘description’ property with new value say ‘desc1’ to desc2’.
  • Repeat the above step i.e update the description to different values. i.e 5 times.
  • Register to command stack undo/redo action listeners and observe the values emitted by bpmn.
  • Do an undo operation. Observe the emitted values from bpmn. It is the same object every time you do a undo operation.
  • Perform undo 5 times. For the 5th time we get the value as ‘defined’. For the first 4 times, old values are getting printed by bpmn but for the 5th time ‘undefined’ is returned which might be the initial value.

We took a separate approach for targeting undo/redo. When ever we are updating any child element we are creating a new extension element and constructing the entire object and calling 'modeling.updateProperties()’. This way we are getting the previous object on performing an undo action.

So instead of creating/constructing entire object every time if a deep clone api is available to clone the extension element this would save our time and code.


You can copy model properties from model element to another using ModdleCopy:

moddleCopy.copyElement(source, target);


I’m getting below error while using moddleCopy
code i written
const bpmnJS = new BpmnJS({
keyboard: {
bindTo: document

let moddleCopy = bpmnjs.get(“moddleCopy”);

ERROR Error: No provider for “moddleCopy”! (Resolving: moddleCopy)

First of all:

Second, I posted a working example. Please have a look at it again. Make sure you’re using the modeler, not the viewer.

I’m using modeler only , this is the version I’m using bpmn-js -3.5.0.

moddleCopy is available in 3.5.0 ?

Compare your code to the example. As you can see it’s working.