Get current selected task


#1

Hi togehter,

i’m working on a project with the bpmn-js.

How can i get the current selected task?

Thanks


#2

Use the selection service to acomplish this:

function MyComponent(selection) {

  var selectedElements = selection.get();
  // [ { id: 'task1_', ... }, { id: 'connection_1', ... } ]

}

#3

I’m listening to the ‘element.mousedown’ event. Based on the Element.Type property I’m building up my own datamodel around a task or another element…

My Code:

function importXML(xml) {
  // import diagram
  bpmnModeler.importXML(xml, function (err) {
    if (err) {
      return console.error(‘could not import BPMN 2.0 diagram’, err);
    }
    var canvas = bpmnModeler.get(‘canvas’);
    canvas.zoom(‘fit-viewport’);
  });
  bpmnModeler.on(‘element.mousedown’, function (event) {
    self.TaskClicked(event.element);
  });
}

function TaskItem(element) {
   // Do your thing here
   var taskID = element.id
   var ElementType = element.type;
}