Get error in connecting programmatically a Task and a DSR object

Hi,
in my code, I create a task obj task and connect it to a DSR obj.

var modeling = modeler.get('modeling');
var elementFactory = modeler.get('elementFactory');
var clientWidth = document.getElementById('js-drop-zone').clientWidth;
const x_task = clientWidth/2 - task_width/2;
var current_Y = 30;
// place Task element
const task = elementFactory.createShape({ type: 'bpmn:Task' });
modeling.createShape(task, { x: x_task, y: current_Y, width: task_width, height: task_height },
  modeler_canvas.getRootElement()
);
modeling.updateLabel(task, 'test');

const in_dsr = elementFactory.createShape({ type: 'bpmn:DataStoreReference' });
modeling.createShape(in_dsr, { x: x_task, y: current_Y - dsr_height - connect_length, width: 40, height: 40 },
modeler_canvas.getRootElement()
);
modeling.connect(in_dsr, task);

When I run this code, the task and the in_dsr element are correctly displayed but when trying to connect them I get the following errors:

unhandled error in event listener

findActualParent@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:16261:13
BpmnOrderingProvider/this.getOrdering@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:16284:19
OrderingProvider/<@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:38639:25
invokeFunction@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:24643:13
./node_modules/bpmn-js/node_modules/diagram-js/lib/core/EventBus.js/EventBus.prototype._invokeListener@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:24494:19
./node_modules/bpmn-js/node_modules/diagram-js/lib/core/EventBus.js/EventBus.prototype._invokeListeners@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:24475:24
./node_modules/bpmn-js/node_modules/diagram-js/lib/core/EventBus.js/EventBus.prototype.fire@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:24436:24
./node_modules/bpmn-js/node_modules/diagram-js/lib/command/CommandStack.js/CommandStack.prototype._fire@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:22568:29
./node_modules/bpmn-js/node_modules/diagram-js/lib/command/CommandStack.js/CommandStack.prototype._internalExecute@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:22610:10
./node_modules/bpmn-js/node_modules/diagram-js/lib/command/CommandStack.js/CommandStack.prototype.execute@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:22365:8
./node_modules/bpmn-js/node_modules/diagram-js/lib/features/modeling/Modeling.js/Modeling.prototype.createConnection@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:35263:22
./node_modules/bpmn-js/lib/features/modeling/Modeling.js/Modeling.prototype.connect@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:9152:15
gotoDiagramSetup@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:171:12
startEditedDiagram@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:185:19
./app/app_edit.js@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:201:21
__webpack_require__@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:20:30
@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:84:18
@http://localhost:8080/bpmn-js-examples/modeler/public/app_edit.bundled.js:87:10

Uncaught (in promise) Error: no parent for DataInputAssociation_10bcwlc in __implicitroot
    findActualParent BpmnOrderingProvider.js:119
    getOrdering BpmnOrderingProvider.js:142
    OrderingProvider OrderingProvider.js:48
    invokeFunction EventBus.js:520
    _invokeListener EventBus.js:371
    _invokeListeners EventBus.js:352
    fire EventBus.js:313
    _fire CommandStack.js:356
    _internalExecute CommandStack.js:398
    execute CommandStack.js:153
    createConnection Modeling.js:242
    connect Modeling.js:85
    gotoDiagramSetup app_edit.js:69
    startEditedDiagram app_edit.js:83
    js app_edit.js:99
    Webpack 3
BpmnOrderingProvider.js:119

Thank you for your help.

For further assistance, please share a CodeSandbox that reproduces your issue in a way that we can inspect it. Thank you!

Have you imported a diagram? You shouldn’t have an element with the ID __implicitRoot in the diagram if you did.

1 Like

That was it! I have been adapting my project to a different use case and did not update the logic to call the importDiagram().
Thank you.