# Retain connections to re-ordered outputs

**URL:** <https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379>\
**Category:** Developing Nodes\
**Created:** [30 August 2021 09:24 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379 "2021-08-30T09:24:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [30 August 2021 09:24 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/1 "2021-08-30T09:24:55Z")

</div>

So,

I am using the `editableList` UI widget, that is also responsible for spawning output pins.  
This all works well, I can add/remove/re-order so on and so forth.

I have a function for `outputLabels` that returns the name of the 'rule', etc etc

However, when I re-order, the logic works, BUT - the original connected wires are still in their position, and not moved around - much like the switch node does.

So I end up with the messages hitting the incorrect connected nodes.

What is the magic ingredient, for retaining the connections to the pins - only having them shifted - likes the pins are?

Thanks

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 August 2021 09:34 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/2 "2021-08-30T09:34:45Z")

</div>

I haven't looked at the source but I imagine it also reorders the wires array. You can see this if you export any node there is a wires property in the object.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [30 August 2021 09:39 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/3 "2021-08-30T09:39:09Z")

</div>

That does sound logical - looking at the switch source - I can't see anything that would hint at the re-ordering of wires.

This is a good area of interest though. 👍

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 August 2021 09:58 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/4 "2021-08-30T09:58:49Z")

</div>

The magic is in the `outputs` property your node sets. Rather than a simple number, you can set it to an object that maps "old" to "new".

I can't be more specific at the moment... stood in a queue for a rollercoaster at Legoland. Have a look at the Switch node for an example.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [30 August 2021 10:00 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/5 "2021-08-30T10:00:24Z")

</div>

Nice!

I'll explore - thanks

Side Note: We want a picture of the moment you pass out 👍

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 August 2021 11:32 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/6 "2021-08-30T11:32:37Z")

</div>

![InShot_20210830_120850003](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/dfde318260d4f69e300a8684d730ac3493de7444.jpeg)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [30 August 2021 14:00 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/7 "2021-08-30T14:00:11Z")

</div>

Ok,

I have studied the switch node - it seems to be doing something **\_i** and **i**  
I don't have a UI element (hidden or otherwise), that controls `outputs`,  
but I am setting my outputs property on `oneditsave`.

via processing the `editableList` array which is working as expected.

My attempts at trying to create an object for `outputs`, simply results in the node just disappearing when being saved. or dragged into the flow.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [30 August 2021 16:13 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/8 "2021-08-30T16:13:14Z")

</div>

On further investigation, I need to set `_outputs` as the new 'change map', assumably this is like a temporary map, for the flow to re-configure its connections.

However, this also does not re-order the wires.

I am setting random numbers for the ID `{"45454354":0,"454354343":1}`,  
this make no difference, and I not able to get the node to work like the switch node.

How is the ID associated to the output? is it based on key order?

I found this, from which I am trying decipher.

> **[Design: Editable port labels · node-red/node-red Wiki](https://github.com/node-red/node-red/wiki/Design:-Editable-port-labels)**
>
> Low-code programming for event-driven applications - Design: Editable port labels · node-red/node-red Wiki

Thanks

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [31 August 2021 19:28 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/9 "2021-08-31T19:28:55Z")

</div>

OK,

I have sussed it.

It seems the connection ordering is dependent on an input control with id `node-input-outputs`  
setting it directly i.e `node.outputs` | `node._outputs` has no affect.

Looking at `editor.js` it will re-order the connections using only the input control.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 September 2021 19:29 UTC](https://discourse.nodered.org/t/retain-connections-to-re-ordered-outputs/50379/10 "2021-09-14T19:29:50Z")

</div>

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