.updateAttributes on a sub-element like bpmn:Documentation

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.

I no longer use documentation elements but if I remember correctly, bpmn:Documentation is part of the “extensionElements” right?

var moddle = bpmnDiagram.get('moddle');
var modeling = bpmnDiagram.get('modeling');

var documentation = moddle.create('bpmn:Documentation');
var extensionElements = moddle.create('bpmn:Documentation');
extensionElements.values = [ documentation ];

modeling.updateProperties(myElement, {extensionElements : extensionElements});

I’m not sure if this is correct, if you have any problem feel free to ask.

Cheers.

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.

Thanks again for your help!

S.

Then you just have to update using an array:

var myDocEntry = moddle.create('bpmn:Documentation');
modeling.updateProperties(myElement, {documentation : [ myDocEntry ]});

Cheers.
Gonzalo.

if you want change documentation’s value, you can try myDocEntry[‘text’] = ‘’

Please do not necrobump old topics. Instead link to this thread from new topic.

I’ve inlined a working answer to this question.

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