Best approach to offer diagram templates?


I would like to offer users the possibility to start a diagram by picking examples from a list of predefined templates, and wonder what is the best way to implement this.

What I am thinking of:

  1. I would create a few templates (like a dozen, which I find relevant for this project) by myself, and would save them in 12 XML files
  2. I would then offer a menu from which the user can pick one of the 12 templates, in order to create his diagram in 1 click (behind the scene, my code would call importXML to initialize the diagram).
  3. he/she would then be able to modify it with the BPMN editor, as usual.
  4. the diagrams would then be executed by Camunda

My concerns:

a) as the same template could be used multiple times to create multiple diagrams (which would then be possibly executed in parallel by Camunda), I think I have to modify the IDs of the activities, once they are read from the XML file, to make sure they are unique across the various created diagrams. Otherwise, this could result in duplicate IDs within the Camunda engine.

→ question 1: is it an issue if activities/links have shared IDs across various process definitions? (e.g. process definition X contains a task with ID activity_123, and process definition Y also contains a task with ID activity_123)

→ question 2: how can I modify all the IDs of my XML templates, and ensure unicity?

b) I could alternatively use copy/paste features and iterate over all the elements of the diagram, but it seems that it would be a huge amount of work, and I guess there are higher level features in BPMNjs to avoid this. Also, I don’t know how the IDs of activities/links are changed when copying/pasting.

Could you please help me by telling what would be the best way to achieve all this?
Many thanks!

I think I have to modify the IDs of the activities, once they are read from the XML file, to make sure they are unique across the various created diagrams.

The modeling toolkit does not offer this capability out of the box, but there is fairly straight forward ways to implement this by replacing IDs in your XML file, mapping them each time to new (unique) IDs.

@bpmn-io/replace-ids is a utility that implements this behavior. It shall be fairly easy for you to replicate that with a regular expression search and replace operation (or re-use the util).

Hope this helps!

1 Like

Many thanks Nikku! Will have a look at this utility.

And regarding question 1, does it hurt if activities/links from various process definitions have the same IDs? Well, I think it’s rather a Camunda-specific question, so it might be off-topic in this thread, but as the IDs are generated by BPMNjs, it’s borderline…

If it is not an issue, I would have nothing to do, which is always good news for lazy people :slight_smile: (but also shortens the application code, which is always safer for developers)

From the Camunda point of view that does not hurt. Definitions must have unique IDs though (think processDefinitionKey in the runtime world.

I do recommend to generate pseudo-random as well as semantic IDs though. It is just a good practice.

1 Like

Thank you again Nikku. Noted. The process definitions are indeed unique already in my case.