# 'Calling' back a node?

**URL:** <https://discourse.nodered.org/t/calling-back-a-node/38391>\
**Category:** Developing Nodes\
**Created:** [2 January 2021 10:37 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391 "2021-01-02T10:37:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [2 January 2021 10:37 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/1 "2021-01-02T10:37:45Z")

</div>

I am developing some custom nodes for one of mine clients, and i got stuck on one part....

What i try to accomplish:  
We have an 'IF' node with two outputs ,  
first output executes first.  
When flow from first output is finished , there is a 'End' node , witch task will be to save the output , and callback the 'if' node and pass some values to it.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/01278877cba8c48594cd87d5fd235687a3099d0d.png)

I just used function nodes for displaying (everything will be a custom node-red node later),

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 January 2021 10:43 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/2 "2021-01-02T10:43:50Z")

</div>

Hi.

I think I understand what you mean, but a suggestion is rather than making this `if` node:  
use a `switch` node and _switch_ the message depending on a message property.

---

<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:** [2 January 2021 10:44 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/3 "2021-01-02T10:44:22Z")

</div>

How is that "IF" and "END" node different to simply using built in nodes in series?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/4858b6cc62f1a1c136ff4f5abff081338e6cab5f.png)

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [2 January 2021 10:51 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/4 "2021-01-02T10:51:47Z")

</div>

Let me set a bigger example here....  
My output string at the end node should be  
'if (output from previous node) { display.printLn }'  
i want to pass it back to the if node , and the if node should just output it...

it is a clients wish on the work flow of the custom nodes i am building for him...

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 January 2021 11:09 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/5 "2021-01-02T11:09:25Z")

</div>

You may need to explain more on what is happening to the payloads in these nodes (the ones that change it) so it is better understood.

This is my best understanding of what you want to do:

```auto
[{"id":"4e2f011c.d78ae","type":"inject","z":"703c61ac.837e1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1280,"y":560,"wires":[["e00c57d5.1901c"]]},{"id":"e00c57d5.1901c","type":"switch","z":"703c61ac.837e1","name":"\"IF\"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"","vt":"str"},{"t":"eq","v":"","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1430,"y":560,"wires":[["1db8d553.5b81db"],["8936c852.60eb5"]]},{"id":"1db8d553.5b81db","type":"function","z":"703c61ac.837e1","name":"Display","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1580,"y":540,"wires":[["91501c3b.87a88"]]},{"id":"91501c3b.87a88","type":"function","z":"703c61ac.837e1","name":"\"END\"","func":"// The paylod MUST be modified here.\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1750,"y":490,"wires":[["e00c57d5.1901c"]]},{"id":"8936c852.60eb5","type":"function","z":"703c61ac.837e1","name":"Something else","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1600,"y":600,"wires":[[]]}]

```

![Screenshot from 2021-01-02 22-12-35](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/c/ecafcb4206cd214f438b0e61a721a88d232f1c6d.png)

---

<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:** [2 January 2021 11:45 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/6 "2021-01-02T11:45:51Z")

</div>

> [@lizzardguki](#):
>
> i want to pass it back to the if node , and the if node should just output it..

Perhaps I am missing the point but I still dont see how that is different to wiring nodes in series.

> [@lizzardguki](#):
>
> it is a clients wish on the work flow of the custom nodes i am building for him...

I would convince your client that is somewhat anti-pattern. the wires in node-red symbolise flow of a msg.

---

<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:** [2 January 2021 12:04 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/7 "2021-01-02T12:04:44Z")

</div>

Give your End node an output and connect it back to the If node input.

Edit, as I see @Trying_to_learn has suggested.

---

<div class="post-metadata">

**Author:** ![Hypnos](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hypnos/32/7566_2.png) [@Hypnos](https://discourse.nodered.org/u/Hypnos)\
**Post date:** [2 January 2021 15:52 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/8 "2021-01-02T15:52:23Z")

</div>

Independent of the question if this makes sense in Node red or not. A possible solution could be by creating a configuration node. The same configuration node has be selected in the configuration of the "if" and the "end" node. The "if" nodes must registere herself to the connected configuration node on creation. When the end node receives the message, it call a function in the configuration node which calls a function in all registered "if" nodes, which sends the messages given.

I'm not sure, but I think I've seen something like this before. Regardless of this, I would prefer the variant with the connection from the end to the if node, because you can see the connection between the nodes.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [2 January 2021 15:57 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/10 "2021-01-02T15:57:24Z")

</div>

There is already this - [do-red (node) - Node-RED](https://flows.nodered.org/node/do-red)

---

<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:** [3 March 2021 15:57 UTC](https://discourse.nodered.org/t/calling-back-a-node/38391/11 "2021-03-03T15:57:28Z")

</div>

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