How to add an startEvent programmatically to the process


Hello everyone,

I need to populate a diagram created from a default XML that only contains a ‘process’ element. The data to create shapes/connections comes from a json object. I’ve managed to add shapes through the modeling service with the “appendShape” function. Although, to achieve this result, my default XML must have a startEvent so that I can get it with the 'ElementRegistry" service and provide it as the ‘source’ parameter to the ‘appendShape’ function.

How can I create a startEvent on a diagram containing only the process element?


You can use Modeling#createShape.

var parent = canvas.getRootElement();

modeling.createShape({ type: 'bpmn:Task' }, { x: 100, y: 100 }, parent);

Have a look at Modeling. You can also use the tests as documentation.


This is exactly what I needed. Worked correctly. It helped a lot, thank you! :smile: