# Flow control issue

**URL:** <https://discourse.nodered.org/t/flow-control-issue/26779>\
**Category:** General\
**Created:** [17 May 2020 00:53 UTC](https://discourse.nodered.org/t/flow-control-issue/26779 "2020-05-17T00:53:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [17 May 2020 00:53 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/1 "2020-05-17T00:53:35Z")

</div>

(Re)starting a flow is easy but how does one stop/reset/initialize a flow?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [17 May 2020 05:59 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/2 "2020-05-17T05:59:43Z")

</div>

By disconnecting the wire from a source node you can stop a flow.

What do you mean with "reset/initialize" ?  
What is the issue you are facing ?

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [17 May 2020 16:10 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/3 "2020-05-17T16:10:15Z")

</div>

@bakman2, thanks for the reply.

> [@bakman2](#):
>
> disconnecting the wire

And Deploy, of course.

I'm new to NR and just playing with many nodes to gain familiarity. To that end I have a function node that uses 2 node context variables, a count and a tally. I know I can just delete them after stopping the flow to reset them to "0" but I'm asking if there's a way to do that, and any initialization, without stopping the flow. It makes no real difference in my experimenting but my real world flows may have similar needs. I know I can use an inject node and a function to manipulate flow and global variables which is what my real flows will use but I'm trying to make sure I'm doing this the "easy" way thus the question.

In some of my real flows I use the schedex node for scheduled lighting and I use an inject node to send a message to the schedex nodes so they will emit the on/off per the schedule upon flow start. It feels a little kludgy to me but it works.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [17 May 2020 19:42 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/4 "2020-05-17T19:42:41Z")

</div>

> [@LosinIt](#):
>
> I know I can just delete them after stopping the flow to reset them to "0" but I'm asking if there's a way to do that, and any initialization, without stopping the flow

You don't have to stop the flow to delete the context, just delete it by using the context sidebar.

![eric](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f64ae5ee4be683f16fd520236d9a31be3bc962b6.jpeg)

You could also do it by adding code in your function node, something like;

```auto
if (msg.payload == "reset") {
context.set("mydata1", 0);
context.set("mydata2", 0);
}

```

Then add an inject node that delivers the string value `reset`.

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [17 May 2020 19:55 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/5 "2020-05-17T19:55:03Z")

</div>

There ya go! I like it. Thanks, @Paul-Reed

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 May 2020 21:50 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/6 "2020-05-17T21:50:26Z")

</div>

> [@Paul-Reed](#):
>
> You could also do it by adding code in your function node, something like;
> 
> ```auto
> if (msg.payload == "reset") {
> context.set("mydata1", 0);
> context.set("mydata2", 0);
> }
> 
> ```
> 
> Then add an inject node that delivers the string value `reset` .

Actually that won't delete the context it will set it to 0. If you want to delete it you need to use `context.set("mydata2");`

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [17 May 2020 22:07 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/7 "2020-05-17T22:07:09Z")

</div>

> [@zenofmud](#):
>
> Actually that won't delete the context it will set it to 0. If you want to delete it you need to use `context.set("mydata2");`

Yes I realize that, but...

> [@LosinIt](#):
>
> I know I can just delete them after stopping the flow **to reset them to "0"**

I assumed he meant 0 and not "0"

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [17 May 2020 22:20 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/8 "2020-05-17T22:20:40Z")

</div>

> [@Paul-Reed](#):
>
> he meant 0 and not "0"

Indeed.

But

> [@zenofmud](#):
>
> If you want to delete it you need to use `context.set("mydata2");`

Is more good info so thanks to both of you.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [17 May 2020 22:32 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/9 "2020-05-17T22:32:31Z")

</div>

Technically, to delete the context, I believe the command should be;  
`context.set("mydata2",undefined);`

---

<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:** [16 July 2020 22:32 UTC](https://discourse.nodered.org/t/flow-control-issue/26779/10 "2020-07-16T22:32:35Z")

</div>

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