How to get the lastest label without clicking canvas area?

Desc: the example of bpmn, when i modify the label of [Scan QR code ] element,for example, i change the label to ‘AAA’. Then, i click the button named “print to console” (Bottom left of the page ),and later i will get the diagram string in the console, but i find that the label of [Scan QR code ] element isn’t ‘AAA’ in the string, it still the previous label “Scan QR code”. But if i click the canvas area before , i can get the right value. So, i try this when i click the button

$('#save-button').click(function(){
        bpmnModeler._emit('commandStack.changed');
        setTimeout(function() {
          exportDiagram()
        }, 1000)
      });

But It still doesn’t work!

I just want to get the right label when i click the button. How can i achieve it ?

Thanks !

There is a feature called diagram-js-direct-editing that is responsible for changing an element’s name. The name will only be changed once the editing of the name is completed. Clicking the canvas does exactly that. To trigger the completion manually, do:

const directEditing = bpmnModler.get('directEditing');

if (directEditing.isActive()) {
  directEditing.complete();
}

And please don’t do that:

This event is fired once a command has been executed. You never want to fire this event manually.