Why does modeling updateProperties method not update extension property into xml file?

I develop my project from the extension property panel demo project, and I want to update an extension property into extension elements, it works fine on control, but it isn’t be updated into the xml, please someone make any suggesions here. Thanks

    const getValue = () => {
        var businessObject = getBusinessObject(element);
        const extensionElements = businessObject.extensionElements || moddle.create('bpmn:ExtensionElements');
        if (extensionElements) {
            var gbsElement = extensionElements.groupBehaviours;
            if (gbsElement) {
                var priority = gbsElement.priority;
                return priority;
            }
            else
                return '';
        }
        else
            return '';
    }

    const setValue = value => {
        var businessObject = getBusinessObject(element);
        const extensionElements = businessObject.extensionElements || moddle.create('bpmn:ExtensionElements');
        var gbsElement = extensionElements.groupBehaviours;
        if (!gbsElement) {
            gbsElement = moddle.create('sfgb:GroupBehaviours');
            extensionElements.groupBehaviours = gbsElement;
        }
        if (gbsElement) gbsElement.priority = value;
        //update condition properties
        return modeling.updateProperties(element, {
            extensionElements
        });
    }

The descriptor file is below:

{
  "name": "Transition",
  "prefix": "sfgb",
  "uri": "http://www.bpmnio.net/schema/sfgb",
  "xml": {
    "tagAlias": "lowerCase"
  },
  "associations": [],
  "types": [
    {
      "name": "Transition Property",
      "extends": [
        "bpmn:SequenceFlow"
      ]
    },
    {
      "name": "GroupBehaviours",
      "properties": [
        {
          "name": "priority",
          "isAttr": true,
          "type": "String"
        }
      ]
    }
  ]
}

The xml content what I expected is here, the priority property should be saved into it:

    <bpmn2:sequenceFlow id="Flow_196cbl1" name="days&#62;=10" sourceRef="Gateway_1iahdo9" targetRef="Activity_1o2nyb1">
      <bpmn2:extensionElements>
           <sfgb:groupBehaviours priority="-1" />
      </bpmn2:extensionElements>
      <bpmn2:conditionExpression>days&gt;=10</bpmn2:conditionExpression>
    </bpmn2:sequenceFlow>
1 Like

Hi,

I had a quick look into the ExtensionElementsUtil to get an Idea how bpmn-js handles it, and it seems for extension elements, you need to use modeling.updateModdleProperties instead of modeling.updateProperties.

If this does not work, please consider sharing a CodeSandbox that reproduces your issue in a way that we can inspect it.

Cheers
Martin

@Martin, Thanks your reply, there is an issue in my script, I have fixed this problem. Some code I can share for developers.

The descriptor file need to be added isMany attribute.

{
  "name": "Transition",
  "prefix": "sfgb",
  "uri": "http://www.bpmnio.net/schema/sfgb",
  "xml": {
    "tagAlias": "lowerCase"
  },
  "associations": [],
  "types": [
    {
      "name": "Transition Property",
      "extends": [
        "bpmn:SequenceFlow"
      ]
    },
    {
      "name": "GroupBehaviours",
      "superClass": [ "Element" ],
      "properties": [
        {
          "name": "priority",
          "isMany": true,
          "isAttr": true,
          "type": "String"
        }
      ]
    }
  ]
}

The getValue and setValue method can be implemented like this.

const getValue = () => {
        var businessObject = getBusinessObject(element);
        const extensionElements = businessObject.extensionElements || moddle.create('bpmn:ExtensionElements');
        if (extensionElements) {
            var gbsElement = getExtensionElement(businessObject, 'sfgb:GroupBehaviours');
            if (gbsElement) {
                var priority = gbsElement.priority;
                return priority;
            }
            else
                return '';
        }
        else
            return '';
    }

    const setValue = value => {
        var businessObject = getBusinessObject(element);
        const extensionElements = businessObject.extensionElements || moddle.create('bpmn:ExtensionElements');
        var gbsElement = getExtensionElement(businessObject, 'sfgb:GroupBehaviours');
        if (!gbsElement) {
            gbsElement = moddle.create('sfgb:GroupBehaviours');
            extensionElements.get('values').push(gbsElement);
        }
        if (gbsElement) gbsElement.priority = value;
        //update condition properties
        return modeling.updateProperties(element, {
            extensionElements
        });
    }


    function getExtensionElement(element, type) {
        if (!element.extensionElements
            || !element.extensionElements.values) {
            return;
        }
        return element.extensionElements.values.filter((extensionElement) => {
            return extensionElement.$instanceOf(type);
        })[0];
    }

This will work for my project. Thanks

1 Like