Issues with copy ,paste ($attrs attribute is copied when i do paste the element)

I’m getting extra attribute called (’$attrs’) , when i copy paste the extension elements for bpmn start element .

I’m following the below example
https://github.com/nikku/bpmn-js-copy-paste-example

copied object

  "$type":"bpmn:StartEvent",
  "id":"StartEvent_41EF596A-A630-46E9-9C49-FD681092CC40",
  "name":"Start",
  "extensionElements":{ 
     "$type":"bpmn:ExtensionElements",
     "values":[ 
        { 
             "$type":"awd:properties",
             "$children":[ 
              { 
                  "$type":"awd:property",
                 "name":"description",
                 "$body":"test"
              }
           ]
        }
     ]
  }
}

**Pasted Object**

"oldBusinessObject":{ 
  "$type":"bpmn:StartEvent",
  "id":"StartEvent_41EF596A-A630-46E9-9C49-FD681092CC40",
  "name":"Start",
  "extensionElements":{ 
     "$type":"bpmn:ExtensionElements",
     "values":[ 
        { 
           "$type":"awd:properties",
           "$attrs":{
             "$children":[ 
              { 
                 "$type":"awd:property",
                 "$attrs":{
                  "name":"description",
                  "$body":"test"
                 }
              }
           ]
          }
        }
     ]
  }
}

**This is the reviver function:**

createReviver(moddle) {
    const elCache = {};
    return (key, object) => {
      if (object && typeof object === 'object' && typeof object.$type === 'string') {
        const objectId = object.id;
        if (objectId && elCache[objectId]) {
          return elCache[objectId];
        }
        const type = object.$type;
        const attrs = Object.assign({}, object);
       delete attrs.$type;
        const newEl = moddle.create(type, attrs);
        if (objectId) {
          elCache[objectId] = newEl;
        }
       
        return newEl;
      }
      return object;
    };
  }

can you please format your code so it would be easier to read?

https://help.github.com/en/articles/creating-and-highlighting-code-blocks

I got the problem here, mistake i did is

i should use the moddle.createAny () instead of moddle.create() for extension elements,

now it s working after replae with moddle.createAny() .

Thanks for your reply on this

This is not the solution to your problem. Format your code and I’m happy to help.

I formatted the above code.
and also
could you please provide any example for copy, paste the custom elements example

Have you created a model extension for your awd namespace?

Which example are you referring to?

After Creating the moddle extension for awd , copy , paste is working fine.
Now I replaced moddle.createAny() with moddle.create()

I’m following the below example.

Thanks for you support

1 Like