I’ve been successful updating attributes like “id” and “name”, but I’m not clear on how to update an attribute (element??) like bpmn:Documentation, which has attributes of it’s own, like “text” and “textFormat”.
When I use updateProperties on id and name, I have a handle to the business object and it works well. If I try to use updateProperties on bpmn:Documentation’s text attribute and I use the same handle to the BO, it just adds the a orphaned and non-standard “text” attribute at the root level of the BO.
I guess I’ll have the same problem with extension elements as I’m having with documentation…though I recall there may be a specific function to update extension elements.
Answer
A bpmn:Documentation element has to be added to the businessObject (BPMN moddle element) that backs up a shape:
var moddle = bpmnDiagram.get('moddle');
var modeling = bpmnDiagram.get('modeling');
var documentation = moddle.create('bpmn:Documentation');
modeling.updateBusinessObject(myElement, myElement.businessObject, {
documentation: [ documentation ]
});
You can find out more about the structure of BPMN moddle elements in the bpmn-moddle BPMN schema.
Thanks @gcalvo . That mostly works and would have worked if documentation was an extension element. You did mis-remember ;-). Documentation is odd in that it sits in business object as its own ModdleElement - but in an array of documentation ModdleElements. I believe that is per the standard.
In any case, yes, I needed to do a moddle.create to create a bpmn:Documentation ModdleElement. Unfortunately, I didn’t know how to pass it into the modeling.updateProperties function because, for documentation, the newly created ModdleElement is actually a member of an array. I am still hack when it comes to javascript and couldn’t figure out how to use updateProperties when the update is a member of an array. I got what I wanted by simply setting it on the updatedObject.businessObject.documentation[0] object path. I guess I lose undo/redo functionality, but that is fine with me.