Attributes of multiple elements are not updating

I am trying to update the attributes of multiple elements by using modeling but after updating all the attributes of elements when I get the updated XML only the last updated element’s property gets updated other element’s attributes didn’t changes.

here is my code

import Modeler from "bpmn-js/lib/Modeler";

const _modeler = new Modeler({ container: '#container', propertiesPanel: { parent: '#properties' } });
const elements_list = [ [element_object , {"attribute_name": "value"}] , ....]
for(let i = 0; i < elements_list .length; i++){
             const modeling = _modeler .get('modeling');
            modeling.updateProperties(elements_list[i][0], elements_list[i][1]);
}

_modeler.saveXML({ format: true }).then({ xml } => console.log(xml));

Where does elements_list come from? It’s hard to reason about this code without context. Do you happen to have a CodeSandbox that reproduces this issue?

1 Like

I am trying to update attributes of the elements

const elements_list = [ [element_object , {“attribute_name”: “value”}] , …]
here : - element_object is bpmn element object and second element id attribute which I want to update

I use for loop to update multiple elements one by one

const elements_list = [ [element_object , {“attribute_name”: “value”}] , …]
for(let i = 0; i < elements_list .length; i++){
const modeling = _modeler .get(‘modeling’);
modeling.updateProperties(elements_list[i][0], elements_list[i][1]);
}

after updating all the elements, I need its updated XML, so I use modeler to get the XML
_modeler.saveXML({ format: true }).then({ xml } => console.log(xml));

but in this XML all the element’s attributes are not updated only the last element’s attribute gets updated in the XML

What I want is an XML in which all the element’s attribute is updated.

No, I don’t have CodeSandbox

What attributes are you trying to update?

1 Like

Url attribute:
url = “/abc/eng/someFile.wav”

I am storing this type of value in attributes

So it’s a custom attribute. Have you created a model extension for this attribute? Otherwise, the attribute will not be serialized.

1 Like

yes, I have created model extension for that attribute, attribute is present in xml

if I update only one element it’s attributes gets updates , but in case of multiple elements only last element’s attribute gets updated in the xml

I’d suggest you debug the code. Is the list actually containing the elements you expect and so on.

1 Like

thanks for the reply @philippfromme

we have list of properties to update in an array… we are using

const modeling = modeler.get('modeling');
modeling.updateProperties(el, attrInfo);

we perform loop on the list to update list of attributes on different elements. But it just update the last element only, like if element has 3 attributes to update then it will apply changes for 3rd element, first 2 it will skip.

my el.businessObject has properties like

image

there is voiceFileInfo attribute that has string json, and i am updating the this voiceFileInfo using this

const attrInfo = {};
attrInfo[key] = value;
modeling.updateProperties(el, attrInfo);

this code works, if i am running this outside the loop, like running this once. But i have list of attributes to update, so the same code m running in for loop. but in that case if there are 3 attributes to update, it will just update the last attribute value.

even i tried this


const extensionParent = bo.extensionElements || moddle.create('bpmn:ExtensionElements');
const property = moddle.create(type, { name: attrName, value: value });
extensionParent.get('values').push(property);

even this

const property = moddle.create("VoiceFilePlayerTask", { name: "voiceFileInfo", value: value });
const modeling = modeler.get('modeling');
modeling.updateProperties(el, property);

this is my descriptor file

"prefix": "voice",

  "types": [

    {

      "name": "VoiceFilePlayerTask",

      "extends": [

        "bpmn:Task"

      ],

      "properties": [

        {

          "name": "voiceFileInfo",

          "isAttr": true,

          "type": "String"

        }

      ]

    }

  ],

@philippfromme if you can help?