Connect task elements programmatically

Hello,
Can you please give some hint and guidance in order to implement below case:

i have a custom task that will be dropped in the diagram then all other tasks will connect to it implictly without using the sequence/Message flow action,
then i would like to produce a bpmn xml files which contains a custom task which has connection to all other tasks but the rendring in the diagram will hide this connection.

Expected Bpmn xml document:

  <?xml version="1.0" encoding="UTF-8"?>
    <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
      <bpmn:process id="Process_1" isExecutable="false">
        <bpmn:startEvent id="StartEvent_1" name="Start">
          <bpmn:outgoing>SequenceFlow_0hft36n</bpmn:outgoing>
        </bpmn:startEvent>
        <bpmn:task id="Task_18d2r4l" name="In Progress">
          <bpmn:incoming>SequenceFlow_0hft36n</bpmn:incoming>
          <bpmn:incoming>SequenceFlow_03ifuok</bpmn:incoming>
          <bpmn:outgoing>SequenceFlow_1jtudln</bpmn:outgoing>
          <bpmn:outgoing>SequenceFlow_0tddfhk</bpmn:outgoing>
        </bpmn:task>
        <bpmn:sequenceFlow id="SequenceFlow_0hft36n" sourceRef="StartEvent_1" targetRef="Task_18d2r4l" />
        <bpmn:endEvent id="EndEvent_0zyl0iw" name="End">
          <bpmn:incoming>SequenceFlow_1jtudln</bpmn:incoming>
          <bpmn:incoming>SequenceFlow_0zw5ha9</bpmn:incoming>
        </bpmn:endEvent>
        <bpmn:sequenceFlow id="SequenceFlow_1jtudln" sourceRef="Task_18d2r4l" targetRef="EndEvent_0zyl0iw" />
        <bpmn:task id="Task_10qizfe" name="Approved">
          <bpmn:incoming>SequenceFlow_0tddfhk</bpmn:incoming>
          <bpmn:outgoing>SequenceFlow_0zw5ha9</bpmn:outgoing>
          <bpmn:outgoing>SequenceFlow_03ifuok</bpmn:outgoing>
        </bpmn:task>
        <bpmn:sequenceFlow id="SequenceFlow_0tddfhk" sourceRef="Task_18d2r4l" targetRef="Task_10qizfe" />
        <bpmn:sequenceFlow id="SequenceFlow_0zw5ha9" sourceRef="Task_10qizfe" targetRef="EndEvent_0zyl0iw" />
        <bpmn:sequenceFlow id="SequenceFlow_03ifuok" sourceRef="Task_10qizfe" targetRef="Task_18d2r4l" />
      </bpmn:process>
      <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="173" y="102" width="36" height="36" />
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape id="Task_18d2r4l_di" bpmnElement="Task_18d2r4l">
            <dc:Bounds x="283" y="80" width="100" height="80" />
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge id="SequenceFlow_0hft36n_di" bpmnElement="SequenceFlow_0hft36n">
            <di:waypoint xsi:type="dc:Point" x="209" y="120" />
            <di:waypoint xsi:type="dc:Point" x="283" y="120" />
            <bpmndi:BPMNLabel>
              <dc:Bounds x="201" y="110" width="90" height="20" />
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNShape id="EndEvent_0zyl0iw_di" bpmnElement="EndEvent_0zyl0iw">
            <dc:Bounds x="569" y="102" width="36" height="36" />
            <bpmndi:BPMNLabel>
              <dc:Bounds x="542" y="138" width="90" height="20" />
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge id="SequenceFlow_1jtudln_di" bpmnElement="SequenceFlow_1jtudln">
            <di:waypoint xsi:type="dc:Point" x="383" y="120" />
            <di:waypoint xsi:type="dc:Point" x="569" y="120" />
            <bpmndi:BPMNLabel>
              <dc:Bounds x="431" y="110" width="90" height="20" />
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNShape id="Task_10qizfe_di" bpmnElement="Task_10qizfe">
            <dc:Bounds x="282" y="203" width="100" height="80" />
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge id="SequenceFlow_0zw5ha9_di" bpmnElement="SequenceFlow_0zw5ha9">
            <di:waypoint xsi:type="dc:Point" x="382" y="243" />
            <di:waypoint xsi:type="dc:Point" x="476" y="243" />
            <di:waypoint xsi:type="dc:Point" x="575" y="133" />
            <bpmndi:BPMNLabel>
              <dc:Bounds x="431" y="168" width="90" height="20" />
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </bpmn:definitions>

Thank you.

You can connect elements programatically, simply by using Modeling#connect(source, target). Elements rendered in the XML are tightly connected to what is visible on the diagram though. As a result, what you request will be hard to achive.

I personally do not think it is a good thing to deliberately hide certain important parts of the diagram from users.

1 Like

Hello Nikku,
Thanks for your response, could you please point me to the below method name:

  1. where the bpmn:task element and bpmndi:BPMNShape is defined when dropped into the diagram?

  2. In which source code file the modeling.connect(source, target) method is implemented?

Thank you in advance
kind regards,

Hello Bpmn Team,
is there any update regarding this request.

kind regards,