cancel
Showing results for 
Search instead for 
Did you mean: 

get BPMN Elements in order

zohaibjabbar
Champ in-the-making
Champ in-the-making
Hi,

I would like to get all Flow Elements in the same order as they appear in the diagram. Currently, I am retrieving list of flow elements like this:

List<FlowElement> elements = model.getMainProcess().getFlowElements()


However, the order of elements is not the same as it is in the BPMN Diagram.

I was thinking to write my own function and order the elements based on the value of source and target of sequence flows. But is there any way I can get elements in order using Activiti functions?

4 REPLIES 4

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,
I do not know about such a function.

Regards
Martin

vasile_dirla
Star Contributor
Star Contributor
Hi,

we cannot talk always about a specific order of the elements in a diagram since there could have loops, gateways, etc..
It's like an algorithm and the execution order of the elements it's not a predictable one since a step could be skipped based on a logical condition.

Can you say which is the order of the elements for this diagram ?

https://upload.wikimedia.org/wikipedia/commons/c/c0/BPMN-DiscussionCycle.jpg

Hi Dirla,

Thanks for your reply.
Yes, I understand that there can be gateways and loops in a process and that some elements can be skipped based on the logic.
I just wanted a function which goes through all elements of bpmn diagram in the order that they appear on canvas. The algorithm would iterate over all flow elements and if some branches comes up (like gateway), then algorithm will select one branch and will keep on iterating just like in depth first search.

So, I wrote my own function which gets all bpmn elements using following function:

<code> List<FlowElement> elements = model.getMainProcess().getFlowElements() </code>

And then I simply treat bpmn as a graph. I select the start element, then iterate over elements using 'Target Ref' value of elements. and if branches comes up then iterate over one branch and push rest of branches on stack.

Can I post code somewhere on Activiti forum in case it can help someone else?

jbarrez
Star Contributor
Star Contributor
Sure, you can post anything you like Smiley Happy