# How to config only one flow between two elements?

**URL:** <https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363>\
**Category:** Modeler\
**Created:** [February 12, 2025, 11:13am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363 "2025-02-12T11:13:16Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 12, 2025, 11:13am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/1 "2025-02-12T11:13:16Z")

</div>

Hi everyone,

I want to config only one flow between two elements. I was tried setup Rule provider with below code, it worked, but when I reconnect connection it has no effect.  
Hope anyone help, thank you so much!

```auto
   (this as RuleProvider).addRule('connection.create', 2500, function (context: BPMNContext) {
        const { source, target } = context;
        const outgoing = source.outgoing ?? [];
        if (outgoing.some((c) => c.target === target)) {
            return false;
        }
    });

```

![image](https://forum.bpmn.io/uploads/default/original/2X/6/6dabe89b71c569e4eec1ff2d8a3d5b64dd05f977.png)

---

<div class="post-metadata">

**Author:** ![jarekdanielak](https://forum.bpmn.io/user_avatar/forum.bpmn.io/jarekdanielak/32/5522_2.png) [@jarekdanielak](https://forum.bpmn.io/u/jarekdanielak)\
**Post date:** [February 12, 2025, 2:21pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/2 "2025-02-12T14:21:33Z")

</div>

I just tried your code and it seems to work as expected. When I add the second connection, it’s being reversed. Third connection is not allowed.

![image](https://forum.bpmn.io/uploads/default/original/2X/4/4f1116eb55c56f0c51a85ed39c2bdad5a0a70600.png)

> when I reconnect connection it has no effect

What do you mean by that?

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 13, 2025, 2:36am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/3 "2025-02-13T02:36:09Z")

</div>

When i reconnect from another, it still allows(image bellow), I just want to disable it.

Here is my code sanbox [https://codesandbox.io/p/devbox/nervous-wilson-fp9svr](https://codesandbox.io/p/devbox/nervous-wilson-fp9svr)

Thanks for your quick reply!  
 ![image](https://forum.bpmn.io/uploads/default/original/2X/5/5e95e53899d1cc1d4f0654bc07e9a34eb9389120.png)

---

<div class="post-metadata">

**Author:** ![philippfromme](https://forum.bpmn.io/user_avatar/forum.bpmn.io/philippfromme/32/2803_2.png) [@philippfromme](https://forum.bpmn.io/u/philippfromme)\
**Post date:** [February 13, 2025, 9:48am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/4 "2025-02-13T09:48:29Z")

</div>

What exactly is the behavior you want? Only one connection between two elements? Or only one incoming and one outgoing connection for each element?

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 13, 2025, 1:36pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/5 "2025-02-13T13:36:36Z")

</div>

I just want maximum 1 connections between 2 elements(same direction). My code worked when I create new connection, but when I change target from another element it does not work.  
 ![image](https://forum.bpmn.io/uploads/default/original/2X/4/4392f2d5d0a5bc51a48cf2c588db8ae8bd19f8cb.png)

---

<div class="post-metadata">

**Author:** ![philippfromme](https://forum.bpmn.io/user_avatar/forum.bpmn.io/philippfromme/32/2803_2.png) [@philippfromme](https://forum.bpmn.io/u/philippfromme)\
**Post date:** [February 13, 2025, 2:46pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/6 "2025-02-13T14:46:39Z")

</div>

For reconnecting existing connections there is a different rule: [bpmn-js/lib/features/rules/BpmnRules.js at develop · bpmn-io/bpmn-js · GitHub](https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/rules/BpmnRules.js#L115) You’ll have to override this rule as well.

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 13, 2025, 2:52pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/7 "2025-02-13T14:52:32Z")

</div>

I tried override ‘connection.reconnect’ rule, but it failed with bpmn:EndEvent element. Could you view my code in sandbox, please. [https://codesandbox.io/p/devbox/nervous-wilson-fp9svr](https://codesandbox.io/p/devbox/nervous-wilson-fp9svr)  
 ![image](https://forum.bpmn.io/uploads/default/original/2X/4/4579d11258bb86f8ec9a74df0b2c06f5b97ed9a7.png)

---

<div class="post-metadata">

**Author:** ![jarekdanielak](https://forum.bpmn.io/user_avatar/forum.bpmn.io/jarekdanielak/32/5522_2.png) [@jarekdanielak](https://forum.bpmn.io/u/jarekdanielak)\
**Post date:** [February 13, 2025, 4:07pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/8 "2025-02-13T16:07:18Z")

</div>

The reason your reconnection logic doesn’t work is that you condition is true when the reconnection is initiated, not giving it a chance to change targets.

You should not run your check when the “new” target is the current target of the connection.

```js
this.addRule("connection.reconnect", 2500, function (context) {
  const { source, target, connection } = context;

  if (connection.target.id === target.id) {
    return;
  }

  if (source.outgoing.some((c) => c.target === target)) {
    return false;
  }
});

```

---

<div class="post-metadata">

**Author:** ![philippfromme](https://forum.bpmn.io/user_avatar/forum.bpmn.io/philippfromme/32/2803_2.png) [@philippfromme](https://forum.bpmn.io/u/philippfromme)\
**Post date:** [February 13, 2025, 4:42pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/9 "2025-02-13T16:42:29Z")

</div>

Please explain again in clear terms what exactly you want to allow and what not.

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 13, 2025, 4:53pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/10 "2025-02-13T16:53:24Z")

</div>

So sorry with my explain, that is not clear.  
Whatever, your solution save my week.  
Thank you so much @jarekdanielak!

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 13, 2025, 4:55pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/11 "2025-02-13T16:55:57Z")

</div>

Yes, this is my mistake about images description. Sorry team!

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 14, 2025, 3:05am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/12 "2025-02-14T03:05:04Z")

</div>

Excuse me sir, could you help me one more question?  
When I drag source of connection, i meet a problem, I describe it in image bellow.  
Thanks sir!  
 ![image](https://forum.bpmn.io/uploads/default/original/2X/7/7a17d2f51ff6b60776458e17113afb579413f663.png)

---

<div class="post-metadata">

**Author:** ![jarekdanielak](https://forum.bpmn.io/user_avatar/forum.bpmn.io/jarekdanielak/32/5522_2.png) [@jarekdanielak](https://forum.bpmn.io/u/jarekdanielak)\
**Post date:** [February 14, 2025, 9:11am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/13 "2025-02-14T09:11:02Z")

</div>

Please describe what is what you are doing step by step, what is happening and what you want to happen.

Do not use screenshots as the only description for your problem or to share code. Share a snippet or CodeSandbox link instead.

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 14, 2025, 11:38am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/14 "2025-02-14T11:38:57Z")

</div>

When I tried the code you provided, it worked when I moved the arrowhead of the connection. However, when I moved the source of the connection, it did not satisfy the condition `connection.target.id === target.id`, so I was still able to connect(which is incorrect).

Here is my CodeSandbox: [https://codesandbox.io/p/devbox/nervous-wilson-fp9svr](https://codesandbox.io/p/devbox/nervous-wilson-fp9svr)

Thank you so much! You are very helpful.

---

<div class="post-metadata">

**Author:** ![jarekdanielak](https://forum.bpmn.io/user_avatar/forum.bpmn.io/jarekdanielak/32/5522_2.png) [@jarekdanielak](https://forum.bpmn.io/u/jarekdanielak)\
**Post date:** [February 14, 2025, 12:28pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/15 "2025-02-14T12:28:54Z")

</div>

> [@milhlhat](#):
>
> However, when I moved the source of the connection, it did not satisfy the condition `connection.target.id === target.id`,

Are you sure about that? Your comment in the CodeSandbox says otherwise (which is correct):

```js
if (connection?.target?.id === target.id) {
  // Drag source of connection allways match condition
  // So, I can't prevent dropping
  return;
}

```

How would you change this condition to only be satisfied when both the connection target and source hasn’t changed?

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 16, 2025, 10:06am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/16 "2025-02-16T10:06:10Z")

</div>

Sorry about my English,  
I just mean the code worked when I moved the arrowhead of the connection. However, when I moved the source of the connection, it did not.  
[https://codesandbox.io/p/devbox/nervous-wilson-fp9svr](https://codesandbox.io/p/devbox/nervous-wilson-fp9svr)

```auto
  this.addRule("connection.reconnect", 2500, function (context) {
    const { source, target, connection } = context;

    if (connection?.target?.id === target.id) {
      return;
    }

    if (source.outgoing.some((c) => c.target === target)) {
      return false;
    }
  });

```

---

<div class="post-metadata">

**Author:** ![jarekdanielak](https://forum.bpmn.io/user_avatar/forum.bpmn.io/jarekdanielak/32/5522_2.png) [@jarekdanielak](https://forum.bpmn.io/u/jarekdanielak)\
**Post date:** [February 17, 2025, 1:11pm UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/17 "2025-02-17T13:11:22Z")

</div>

I’d suggest you come back to my last reply and try to adjust the conditional statement to also check the connection target. I’m sure you can figure this out and learn something in the process. 🙂

---

<div class="post-metadata">

**Author:** ![milhlhat](https://forum.bpmn.io/user_avatar/forum.bpmn.io/milhlhat/32/5592_2.png) [@milhlhat](https://forum.bpmn.io/u/milhlhat)\
**Post date:** [February 19, 2025, 5:00am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/18 "2025-02-19T05:00:13Z")

</div>

Finally, I found the solution, I need to check one more condition. I send my code here to help someone facing same issue. Thanks support team so much!

```auto

  this.addRule("connection.reconnect", 2500, function (context) {
    const { source, target, connection } = context;

    if (
      connection?.target?.id === target.id &&
      connection?.source?.id === source.id
    ) {
      return;
    }

    if (source.outgoing.some((c) => c.target === target)) {
      return false;
    }
  });

```

[https://codesandbox.io/p/devbox/nervous-wilson-fp9svr](https://codesandbox.io/p/devbox/nervous-wilson-fp9svr)

---

<div class="post-metadata">

**Author:** ![system](https://forum.bpmn.io/uploads/default/original/2X/b/b534893973385c2d302b38572464112e4adae002.png) [@system](https://forum.bpmn.io/u/system)\
**Post date:** [February 26, 2025, 5:00am UTC](https://forum.bpmn.io/t/how-to-config-only-one-flow-between-two-elements/14363/19 "2025-02-26T05:00:53Z")

</div>

Closed on February 26, 2025, 5:00am UTC

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