Add programaticall multiple Pools

I want to add multiple BPMN-Pools with a loop. I tried somthing like this:

var modeling = bpmnModeler.get('modeling');
var customersArray = participants.split(',');       	 
var parent = canvas.getRootElement();        	 
var yValue = 50;

for (let customer of customersArray) {
   modeling.createShape({ type: 'bpmn:Participant', name:customer}, { x: 100, y: yValue, width: 500, height: 250}, parent);
  yValue += 305;

I think the Problem is, that i need to create First a Process for every Pool and then link them. But I dont know how.

And further i want to set the name for the pool. How is that possible? I tested it in the create Shape Option, but this doesnt work.

Hi @wildix!

The ElementFactory#createParticipantShape offers a helper to create bpmn:Participant elements which an attached bpmn:Process element. This returns a participant shape which can be added to the canvas. For setting the name you will have to update the shapesname` property. So something like this

var elementFactory = modeler.get('elementFactory'),
    modeling = modeler.get('modeling'),
    canvas = modeler.get('canvas');

var parent = canvas.getRootElement(),
  participant1 = elementFactory.createParticipantShape(),
  participant2 = elementFactory.createParticipantShape(); = 'A'; = 'B';

modeling.createShape(participant1, { x: 350, y: 200 }, parent);

// turned into collaboration
parent = canvas.getRootElement();

modeling.createShape(participant2, { x: 350, y: 500 }, parent);

Will lead to this


Note: Creating the first participant in the process will turn the whole diagram to a collaboration for adding another participants

1 Like

Thanks for your Help!