How to add BPMN documentation element to XML

I know it works if I add a property
cmdHelper.updateProperties(element, properties);

but now I want to write the documentation element

<process id="Key" name="name">
    <documentation>xxx</documentation>
</process >

I copied and wrote documentation from it, but nothing happened

aa8a2b8049cfc5cbc4772f2967c2aa5

I’m using cmdHelper.setList(element, businessObject, 'documentation', newObjectList);

It outputs to the console normally, but is not generated in XML

Or there may be other method calls that can generate documentation elements

It bothered me for a few days

Thanks in advance

Can you please post actual code instead of screenshots?

I’m sorry

I use setList method to add documentation element

This is the method I wrote before, But this doesn’t generate elements properly

import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory'
import CmdHelper from 'bpmn-js-properties-panel/lib/helper/CmdHelper.js'
var ModelUtil = require('bpmn-js/lib/util/ModelUtil')
...
addProperties(properties) {
      const { bpmnModeler, element } = this
      const modeling = bpmnModeler.get('modeling')
      const moddle = bpmnModeler.get('bpmnFactory')
      var newObjectList = moddle.create('bpmn:Documentation', { text: properties })
      CmdHelper.setList(element, ModelUtil.getBusinessObject(element), 'documentation', newObjectList)
}

Now I changed it to add elements but it is too much trouble

addProperties(properties) {
      const { bpmnModeler, element } = this
      const moddle = bpmnModeler.get('bpmnFactory')
      var newObjectList = moddle.create('bpmn:Documentation', { text: properties })
      bpmnModeler.get('elementRegistry').get(element.id).businessObject.conditionExpression = newObjectList
}

I think there should be a simpler way of writing, so I want to ask you

(For example, I want to add listeners, it will fail again)

Is there a unified interface to add BPMN elements

Thank you very much

Now I found that using moddle.create() can create the elements I need

But this is limited to existing DMPN elements

updateProperties(properties) {
      const { bpmnModeler, element } = this
      const moddle = bpmnModeler.get('bpmnFactory')
      var newObjectList = moddle.create('bpmn:ExtensionElements')
      var connector = moddle.create('flowable:field')
      connector.$parent = newObjectList
      bpmnModeler.get('elementRegistry').get(element.id).businessObject.extensionElements = newObjectList
}

What should I do now if I want to add a Flowable element?

For example, now I need to add flowable:field,Is there any good way to achieve it

<extensionElements>
    <flowable:field name="key">
          <flowable:string><![CDATA[value]]></flowable:string>
    </flowable:field>
</extensionElements>

I think this example can be a good starting point for creating custom elements

Can you please post solved code?

I think you can try this way
for example:

const documentation = bpmnInstance.bpmnFactory.create(
‘bpmn:Documentation’,
{
text: value,
}
);

  bpmnInstance.modeling.updateModdleProperties(
    bpmnInstance.element,
    businessObject,
    {
      documentation: [
        ...businessObject.get('documentation'),
        documentation,
      ],
    }
  );