How can I get the process ID or name of my current model?

I have an instance of BpmnModeler containing my model.

var modeler = new BpmnModeler({
  container: '#bpmn-canvas'
});

I also have an open method to import an existing model:

  modeler.importXML(xml, function(err) {
    if (err) {
      container
        .removeClass('with-diagram')
        .addClass('with-error');

      container.find('.error pre').text(err.message);

      console.error(err);
    } else {
      container
        .removeClass('with-error')
        .addClass('with-diagram');
    }
  });

My question now is, how can I get the attribute values ID or NAME from the process of my imported model? In BPMN the element I mean looks like this:

<bpmn2:process id=“ticket” name=“Ticket” isExecutable=“false”>

Thanks for any help

===
Ralph

Hi!

You can achieve that via canvas.getRootElement.

const canvas = modeler.get('canvas');

const rootElement = canvas.getRootElement();

console.log('Process Id:', rootElement.id);
console.log('Process Name:', rootElement.businessObject.name);

Checkout this sandbox for more details.

In case the process is not the root element of your process diagram, you can use the elementRegistry to get access to all processes.

import { is } from 'bpmn-js/lib/util/ModelUtil';

const elementRegistry = modeler.get('elementRegistry');

console.log(
  elementRegistry.filter(function (element) {
    return is(element, 'bpmn:Process');
  })
);

Thanks a lot! That was exactly I was searching for.

I guess I have missed an important part of the documentation. Can you please point me to the location where I can find the object hierarchy of a BPMN rootElement? Just to avoid more newcomer questions :wink:

You can find a detailed overview of the BPMN metamodel we use under the hood inside bpmn-moddle.

Note that we use the businessObject to mirror the XML information for each element on the canvas.