Setting an extension element node value

Hi guys, how do I programmatically set a node value (of an extension element) using moddle in javascript ? Lets say I have the following model extension:

{
  name: "myExtendableElements",
  prefix: "myElems",
  uri: "myUri.org/bpmn",
   xml: {
    tagAlias: 'lowerCase',
  },
  associations: [],
  types: [
     {
      name: 'MyExtendedElement',
      superClass: ['Element'],
      properties: [{ name: 'body', isAttr: false, type: 'String' }],
    }
  ]
}

Now, creating the extended element and setting its value like

const extensionElements = moddle.create('bpmn:ExtensionElements');
 const newCustomField = moddle.create(`myElems:myExtendedElement`, {
          body: 'some-custom-value',
    });
extensionElements.get('values').push(newCustomField);
modeling.updateProperties(element, {
      extensionElements: extensionElements,
});

produces the following xml

<extensionElements>
        <myElems:myExtendedElement>
            <myElems:body>some-custom-value</myElems:body>
        </myElems:myExtendedElement>
</extensionElements>

while my desired output would be without the <myElems:body> tag, like

<extensionElements>
        <myElems:myExtendedElement>some-custom-value</myElems:myExtendedElement>
</extensionElements>

How do I achieve this, what did I do wrong?

Ah I think I figured it out, my body in properties should have an isBody: true flag, correct?

1 Like

That is correct (cf. bpmn-moddle, moddle-xml documentation).

In meta-modeling a property may be an attribute, body, or entirely virtual.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.