Hi, I am trying to append shape using elementRegistry as below between two events for bpmn from UI which is displaying bpmn diagram in a flowchart The flow chart has a button after each event/ task to add any usertask in between .
I have tried below approach:
- remove existing connection between source and event.
- append new task to source
- connect source and event.
the xml generated for the flow chart looks very weird in bpmn.io as below
const processId = this.bpmn.get('canvas').getRootElement().id;
const process = this.elementRegistry.get(processId);
let sequenceFlowObjectArray = this.getAllDiagramElements().sequenceFlowObject;
// removing old connection
this.modeling.removeConnection(this.elementRegistry.get(sequenceFlowObjectArray[index].id));
const sourceEvent = this.elementRegistry.get(item.sourceEventId);
const oldTargetEvent = this.elementRegistry.get(item.targetEventId);
// create shape
let newUserTask = this.elementFactory.createShape({ type: 'bpmn:UserTask' });
// connect shape to source
this.modeling.appendShape(sourceEvent, newUserTask, { x: 400, y: 100 }, process);
const flow1 = this.getNewFlow(sourceEvent.id, newUserTask.id)[0];
// connect shape to previous target
newUserTask = this.elementRegistry.get(flow1.businessObject.targetRef.id);
this.modeling.connect(newUserTask, oldTargetEvent);
Can you help out? or suggest another way to add user task?