How to know which element is connected (sequenceflow) to a task


Is it possible to get information from the connected tasks?
In this example you see a starter and 2 tasks (1, 2). Is it possible to find out in code which task is connected to task 2?

<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="" xmlns:bpmn2="" xmlns:bpmndi="" xmlns:dc="" xmlns:di="" id="sample-diagram" targetNamespace="" xsi:schemaLocation=" BPMN20.xsd">
  <bpmn2:process id="Process_1" isExecutable="false">
    <bpmn2:startEvent id="StartEvent_1">
    <bpmn2:task id="Task_1wzwxyu" name="1">
    <bpmn2:sequenceFlow id="SequenceFlow_1ocbk4v" sourceRef="StartEvent_1" targetRef="Task_1wzwxyu" />
    <bpmn2:task id="Task_1ycg1p3" name="2">
    <bpmn2:sequenceFlow id="SequenceFlow_0mizci7" sourceRef="Task_1wzwxyu" targetRef="Task_1ycg1p3" />
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="202" y="52" width="36" height="36" />
      <bpmndi:BPMNShape id="Task_1wzwxyu_di" bpmnElement="Task_1wzwxyu">
        <dc:Bounds x="290" y="30" width="100" height="80" />
      <bpmndi:BPMNEdge id="SequenceFlow_1ocbk4v_di" bpmnElement="SequenceFlow_1ocbk4v">
        <di:waypoint x="238" y="70" />
        <di:waypoint x="290" y="70" />
      <bpmndi:BPMNShape id="Task_1ycg1p3_di" bpmnElement="Task_1ycg1p3">
        <dc:Bounds x="450" y="30" width="100" height="80" />
      <bpmndi:BPMNEdge id="SequenceFlow_0mizci7_di" bpmnElement="SequenceFlow_0mizci7">
        <di:waypoint x="390" y="70" />
        <di:waypoint x="450" y="70" />

I know I can use the eventBus to get the different events and information from them, but I can’t find where to see if a task is connected and if so from where he is connected to.

Any help is appreciated.

Kind regards

You can find this out by accessing the businessObject of an element

var elementRegistry = modeler.get('elementRegistry'),
  task = elementRegistry.get('Task_1ycg1p3'),
  businessObject = task.businessObject;

var outgoingConnections = businessObject.outgoing;
var incoming = businessObject.incoming;

Which will get you the connections for the task. With them, you could then indirectly get the connected elements with the outgoing and incoming properties once again.

1 Like

Thank you for the second time today Niklas :+1: