Get Elements In the Order of Flow In Canvas

I’m looking for an API or any customization I can do to get the Elements in the same order as they are in the Canvas.

We have a custom implementation that requires us to maintain the flow of control through the process and decide on the next possible steps even before the step could be executed. Get the elements order could help us achieve the same.


How would you define an order, considering a process is a graph but not a list? We do not have an API doing what you are trying to achieve.

We have however a token simulation plugin that you might find interesting in case what you mean is following a path from a StartProcess to an EndProcess.

Keep in mind that bpmn-js (and therefore Camunda Modeler) is only a visual tool, it has not and should not have BPM execution semantics. The plugin I sent you does not represent what actually is going on when a BPM engine executes your process.


Thanks for the quick response, we understand bpmn-js is a visual tool.
We are just looking for ways to achieve this requirement of ours with help of some internal bpmn-js module.

Token Simulation plugin is very useful and it is considered for another use case of ours.
Unfortunately it doesn’t suffice this ordering requirement.

We need to get the elements numbered as 1, 2, 3 and when a gateway’s are reached, it would become 3a, 3b, 3c, 4a, 4b, 4c and when they are joined back it would continue to 5, 6.


We don’t provide an API for that.

You may however try to construct a Graph structure given a diagram:

  1. Events, gateways and tasks are vertices of the Graph
  2. Sequence flows are the edges between two vertices.

Once you have the Graph constructed, you may traverse it from given starting vertex to an end vertex. You may even find the shortest path between two nodes using Dijsktra or AStar algorithms.

You may use the ElementRegistry module to get individual elements of your diagram. Refer to this question to see how you can use the ElementRegistry module.

Good luck!