Select the bpmn element by clicking the custom button on the canva

Hi,

I have seen one of the post here (How can I fire the 'create.task' action when user drops a custom element in the canvas?) and I want to achieve something similar. So in this example, bpmn-js Sandbox (forked) - CodeSandbox when we click the button then new task is created.

What I want to achieve is following: Imagine we already have a task and when I click it it shows me some properties. Now if I add some external button and if i click it, it should select already created task. How is it possible to do?

Hi @userk , welcome!

There are certain events and modules you can use to listen for this and apply your custom logic.

Imagine we already have a task, and when I click it shows me some properties

// listen on element click events
const eventBus = modeler.get('eventBus');

eventBus.on('element.click', function(event) {

  const element = event.element;

  // do whatever you want, e.g. access properties

});

Now if I add some external button and if i click it, it should select already created task.

// select an element on the canvas
const elementRegistry = modeler.get('elementRegistry');
const selection = modeler.get('selection');

const element = elementRegistry.get('someElementId');

selection.select(element);

Thanks a lot for your help!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.