Accessing the model-structure in javascript

Hello everyone,

I am currently working on a web application that shall be able to analyze BPMN models.
First, models should be uploaded to the web application. Then the web application should identify certain logical blocks in the model automatically. Those logical blocks could be OR-blocks or loops for example:
Analyzing_Model

In order to identify these logical blocks in my code, I have to somehow access the general structure of the process model.

I can already upload BPMN models to my web application and visualize them using the “viewer” of bpmn-js. Now I need a variable where all the elements of the uploaded process are stored in a structured and easily accessible way.
Is there a way to access the structure of the model using bpmn-js? Is it already stored somewhere?

Thanks in advance for any help I receive.

You can use the Element Registry to access all shapes and connections on the diagram. This example should be helpful: bpmn-js-examples/README.md at master · bpmn-io/bpmn-js-examples · GitHub

1 Like

The Element Registry does indeed store all shapes and connections of the business process. However, as far as I can tell, the order of the elements is not stored in a structured way.

I am looking for a variable, where shapes are stored in a way that reflects the structure of the business process.
Like in the following business process:
sequence

Here it would make sense to store the elements in the following order:
StartEvent → SequenceFlow_1 → Task_1 → SequenceFlow_2 → Task_2 → SequenceFlow_3 → EndEvent

Of course, this becomes more complex when there are parallel structures within the business process as shown in the initial example.
I thought that there might be a variable that stores shapes in a “structured” way, that reflects the structure of the business process itself.

It is possible, that what I am asking for isn’t implemented in bpmn-js, since storing elements in a more structured way is not necessarily needed for modeling business processes.
I might have to develop a solution by myself, by using the “outgoing” and “incoming” parameters of each shape, to build a structure which allows me to analyze the business process in the code.

Anyways, thanks for your help, it is very much appreciated.

Perhaps it will be useful to check out how bpmnlint traverses the serialisation part of the diagram: bpmnlint/traverse.js at master · bpmn-io/bpmnlint · GitHub

2 Likes