# Help creating re-usable subflows (or nodes ?)

**URL:** <https://discourse.nodered.org/t/help-creating-re-usable-subflows-or-nodes/48605>\
**Category:** General\
**Created:** [19 July 2021 20:32 UTC](https://discourse.nodered.org/t/help-creating-re-usable-subflows-or-nodes/48605 "2021-07-19T20:32:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaptorUK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/raptoruk/32/46988_2.png) [@RaptorUK](https://discourse.nodered.org/u/RaptorUK)\
**Post date:** [19 July 2021 20:32 UTC](https://discourse.nodered.org/t/help-creating-re-usable-subflows-or-nodes/48605/1 "2021-07-19T20:32:43Z")

</div>

Hi folks,

I'm looking for a little advice, I'm trying to make some re-usable code for a project I'm working on, it's a RS485 comms library which is used to talk to a bespoke bit of hardware The comms takes the form of a 4 letter ID and can be a read, write or read-write to read and write various parameters.

I've done something similar to talk to this hardware using LabVIEW, I put the IDs into a Typedef so they can be selected/picked from a list.

Is there anything similar I can do with Node Red ?

I have over 100 ID, with maybe a common use subset of 20, I don't really want to create a subflow for each of these 20 IDs if I can help it. I could just type the ID in each time I use a subflow . . . but if I have a typo and don't realise it I'll end up tearing my hair out . . .

Suggestions ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 July 2021 20:47 UTC](https://discourse.nodered.org/t/help-creating-re-usable-subflows-or-nodes/48605/2 "2021-07-19T20:47:13Z")

</div>

How do you want to choose the id? Is it entered via a dashboard field or something similar? Is this a run-time choice (in which case you could use a dropdown in the dashboard) or design time (so in the editor).

---

<div class="post-metadata">

**Author:** ![RaptorUK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/raptoruk/32/46988_2.png) [@RaptorUK](https://discourse.nodered.org/u/RaptorUK)\
**Post date:** [19 July 2021 20:50 UTC](https://discourse.nodered.org/t/help-creating-re-usable-subflows-or-nodes/48605/3 "2021-07-19T20:50:07Z")

</div>

Hi Colin,

no it's not a runtime thing, it's a development thing. I'd really like to be able to pick it from a list in a node . . . but can't see a way of doing that.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 July 2021 20:55 UTC](https://discourse.nodered.org/t/help-creating-re-usable-subflows-or-nodes/48605/4 "2021-07-19T20:55:03Z")

</div>

You can enter all id's in a select box in the subflow properties, then when you use the subflow you can select the id. The id can the be retrieved using env.get().  
e.g.

```auto
[{"id":"a7cac120.69305","type":"subflow","name":"","info":"","category":"","in":[{"x":50,"y":30,"wires":[{"id":"e3ded4f.d786628"}]}],"out":[{"x":560,"y":100,"wires":[{"id":"e3ded4f.d786628","port":0}]}],"env":[{"name":"id","type":"str","value":"asdf","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"qwer"},"v":"qwer"},{"l":{"en-US":"asdf"},"v":"asdf"}]}}}],"color":"#DDAA99"},{"id":"e3ded4f.d786628","type":"function","z":"a7cac120.69305","name":"","func":"msg.payload=env.get(\"id\") || 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":160,"wires":[[]]},{"id":"77534080.a19b78","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":3960,"wires":[["5062b101.f16c58"]]},{"id":"5062b101.f16c58","type":"subflow:a7cac120.69305","z":"c74669a0.6a34f8","name":"","env":[],"x":320,"y":4000,"wires":[["861a6d98.3f33"]]},{"id":"861a6d98.3f33","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":3980,"wires":[]}]

```

I entered two id's which you can select when you edit the subflow when you want to use it.

---

<div class="post-metadata">

**Author:** ![RaptorUK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/raptoruk/32/46988_2.png) [@RaptorUK](https://discourse.nodered.org/u/RaptorUK)\
**Post date:** [19 July 2021 21:11 UTC](https://discourse.nodered.org/t/help-creating-re-usable-subflows-or-nodes/48605/6 "2021-07-19T21:11:12Z")

</div>

> [@E1cid](#):
>
> You can enter all id's in a select box in the subflow properties, then when you use the subflow you can select the id.

Terrific, exactly what I need, thank you. 😃

---

<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:** [2 August 2021 21:11 UTC](https://discourse.nodered.org/t/help-creating-re-usable-subflows-or-nodes/48605/7 "2021-08-02T21:11:44Z")

</div>

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