Add Task to board programmatically

Hello guys, amazing work on this library ! I have some side project with bpmn.io and fighting an issue.

I didn’t find the answer on forum, sorry if duplicate.

what is the best approach to add Task element programmatically ?

I have a dialog where user fills the position of Task (x and y coordinates) and optionally fills Label for Task and then hit create button.
So basically same data as if it was done using mouse and element from modeler palette.

How can I add a new Task element to board on location of [x,y] with label ?
Only thing i found was using
modeling.createShape() but don’t know what should I pass inside this method.

Can someone please show how to for example add a new Task element on coordinates x=100,y=200 with label “test” ?

Many thanks, Natalia

First create the model element, then add it to the canvas:

const task = elementFactory.createShape({
  type: 'bpmn:Task',
  name: 'Foo'
});

const position = {
  x: 100,
  y: 100
};

modeling.createShape(task, position, parent);

Thank you so much, you are amazing !
One last question though, the parent object in modeling#createShape method is the canvas right ?

The parent is whatever you want it to be. It can be the parent process or collaboration or for example a sub-process or a participant.