# \`on start\` tab confused how to use

**URL:** <https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353>\
**Category:** General\
**Created:** [6 January 2024 21:15 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353 "2024-01-06T21:15:43Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [6 January 2024 21:15 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/1 "2024-01-06T21:15:43Z")

</div>

Folks, I'm writing/debugging a `subflow`. (My favorite thing)

But I'm stuck on the `on start` tab.

Reading a link I see this as an example:

```auto
if (context.get("counter") === undefined) {
    context.set("counter", 0)
}

```

Which is fair enough, but alas it doesn't quite cover my needs.

Subflows invariable (ok, maybe not) need variables.  
So I'm trying to set up the `function` node to read the variables and use them.

If they aren't set, I want it to use _default_ values.

So....

```auto
// Code added here will be run once
// whenever the node is started.
if (env.get("topic") == undefined)
{
    context.set("topic","topic");
}

```

Is ideally what I want to do, but this opens a can of worms what if `env.get("topic")` **IS** set?

Without posting the whole subflow - which I don't mind doing - what is the way out for me so if the topic isn't defined it is set to .... a default?  
Thanks in advance.

---

<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:** [6 January 2024 21:28 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/2 "2024-01-06T21:28:02Z")

</div>

Hi @Trying_to_learn

I may have this wrong, but can you not do in your `on start`?:

```auto
const value = env.get("topic") || "Your Default"
context.set("topic", value);

```

This way `context.topic` is iether

- What was provided OR
- A default that you decide

---

<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:** [6 January 2024 21:33 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/3 "2024-01-06T21:33:04Z")

</div>

Well, what I posted won't work because it is setting a `context` depending on an `env` variable.

Which leaves the stated problem that if I test if the `env` is (or not) set, and then set the `context` the code in the main part of the node won't work correctly.

I'll give that a go though as I am not getting the result I want.

Sorry, I just got caught with this 2-3 hours ago when something else went wrong and I was debugging it.

I seem to live in a world of _worms_ (from open cans) and am trying to get this one resolved ASAP.

I'll post back soon.

# ALAS

No, sorry that doesn't work.

This is what I get:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc65689977f54f70f31f1927b74081d5d40c0c0c.png)

_Blank_ (empty) topic.  
Not `Your default`. I left it as that only for testing.  
But it doesn't seem to work.

Mind if I post the subflow?

---

<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:** [6 January 2024 21:36 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/4 "2024-01-06T21:36:50Z")

</div>

This is the subflow as is at this date:

```auto
[{"id":"5b2f1c1e34d60f19","type":"subflow","name":"3 Press button","info":"2024 01 07\n==\n\nHuge bug found and fixed.\n\nStill have a bug with code if the\n`topic` is not set.\n\nBut now better than what it was.","category":"","in":[{"x":70,"y":190,"wires":[{"id":"ec5080f153f43d22"}]}],"out":[{"x":840,"y":190,"wires":[{"id":"ee1c20a8875e36cc","port":0}]},{"x":840,"y":270,"wires":[{"id":"10d2bd1bfc555db3","port":0}]}],"env":[{"name":"startat","type":"num","value":"","ui":{"label":{"en-US":"start at"},"type":"input","opts":{"types":["num"]}}},{"name":"hold","type":"bool","value":"true","ui":{"type":"input","opts":{"types":["bool"]}}},{"name":"topic","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"Message 1","type":"str","value":""},{"name":"Message 2","type":"str","value":""},{"name":"Message 3","type":"str","value":""},{"name":"colour 1","type":"str","value":""},{"name":"colour 2","type":"str","value":""},{"name":"colour 3","type":"str","value":""},{"name":"fontclr 1","type":"str","value":""},{"name":"fontclr 2","type":"str","value":""},{"name":"fontclr 3","type":"str","value":""}],"meta":{},"color":"#DDAA99","inputLabels":["Input"],"outputLabels":["Output","Loop back to button node"],"icon":"node-red-dashboard/ui_button.png"},{"id":"9c628490f5a7ab36","type":"switch","z":"5b2f1c1e34d60f19","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":230,"y":270,"wires":[["625edd1859414ac8"],["2ed89392aefd3ac3"],["75984bf53702c1ac"]]},{"id":"625edd1859414ac8","type":"change","z":"5b2f1c1e34d60f19","name":"1","rules":[{"t":"set","p":"text","pt":"msg","to":"Message 1","tot":"env"},{"t":"set","p":"bgc","pt":"msg","to":"colour 1","tot":"env"},{"t":"set","p":"fontclr","pt":"msg","to":"fontclr 1","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":230,"wires":[["10d2bd1bfc555db3"]]},{"id":"2ed89392aefd3ac3","type":"change","z":"5b2f1c1e34d60f19","name":"2","rules":[{"t":"set","p":"text","pt":"msg","to":"Message 2","tot":"env"},{"t":"set","p":"bgc","pt":"msg","to":"colour 2","tot":"env"},{"t":"set","p":"fontclr","pt":"msg","to":"fontclr 2","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":270,"wires":[["10d2bd1bfc555db3"]]},{"id":"75984bf53702c1ac","type":"change","z":"5b2f1c1e34d60f19","name":"3","rules":[{"t":"set","p":"text","pt":"msg","to":"Message 3","tot":"env"},{"t":"set","p":"bgc","pt":"msg","to":"colour 3","tot":"env"},{"t":"set","p":"fontclr","pt":"msg","to":"fontclr 3","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":310,"wires":[["10d2bd1bfc555db3"]]},{"id":"ec5080f153f43d22","type":"function","z":"5b2f1c1e34d60f19","name":"","func":"node.warn(\"ENV topic \" + env.get(\"topic\"));\nnode.warn(\"context topic \" + context.get(\"topic\"));\n\n// Get \"start value\"\nif (msg.topic == \"startup\")\n{\n context.set(\"previous\",msg.payload-1);\n}\n\nif (msg.payload == \"reset\")\n{\n context.set(\"previous\",0);\n return;\n}\n\nvar max = 4;\nvar previous = context.get(\"previous\") || 0;\nprevious = (previous + 1) % max;\ncontext.set(\"previous\",previous);\n\nif (previous == 0)\n{\n previous = 1;\n context.set(\"previous\",1);\n}\nmsg.payload = previous;\nmsg.topic = env.get(\"topic\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\nconst value = env.get(\"topic\") || \"Your Default\"\ncontext.set(\"topic\", value);\n","finalize":"","libs":[],"x":390,"y":190,"wires":[["9c628490f5a7ab36","ee1c20a8875e36cc"]]},{"id":"ee1c20a8875e36cc","type":"trigger","z":"5b2f1c1e34d60f19","name":"Delay","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"350","extend":true,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":190,"wires":[["20347974efa46acb"]]},{"id":"20347974efa46acb","type":"change","z":"5b2f1c1e34d60f19","name":"$hold","rules":[{"t":"set","p":"hold","pt":"msg","to":"hold","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":535,"y":150,"wires":[["52f023f6a52afa5b"]],"l":false},{"id":"52f023f6a52afa5b","type":"switch","z":"5b2f1c1e34d60f19","name":"if FALSE","property":"hold","propertyType":"msg","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":585,"y":150,"wires":[["7d8c55ef2950c72a"]],"l":false},{"id":"7d8c55ef2950c72a","type":"change","z":"5b2f1c1e34d60f19","name":"reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":635,"y":150,"wires":[["ec5080f153f43d22"]],"l":false},{"id":"10d2bd1bfc555db3","type":"junction","z":"5b2f1c1e34d60f19","x":550,"y":270,"wires":[[]]},{"id":"d87556ee78f63d9c","type":"subflow:5b2f1c1e34d60f19","z":"88de1ac2.8b8c38","name":"","env":[{"name":"startat","value":"0","type":"num"},{"name":"Message 1","value":"ALL","type":"str"},{"name":"Message 2","value":"BLOCK","type":"str"},{"name":"Message 3","value":"ONE","type":"str"},{"name":"colour 1","value":"limegreen","type":"str"},{"name":"colour 2","value":"violet","type":"str"},{"name":"colour 3","value":"fuchsia","type":"str"},{"name":"fontclr 1","value":"black","type":"str"},{"name":"fontclr 2","value":"black","type":"str"},{"name":"fontclr 3","value":"black","type":"str"}],"x":1640,"y":280,"wires":[["e20a43ccb6ec319a"],[]]}]

```

---

<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:** [6 January 2024 21:43 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/5 "2024-01-06T21:43:55Z")

</div>

My understanding is, you **can't** set an `env` in code ( I could be wrong here)

So you (instead) need to use an area that can be set during runtime ( i.e `context`) therefore use `env` as the **possible** value - to be used

1. in `On Start` set `context` to the provided (env value) OR use a default of your choice

```auto
const value = env.get("topic") || "Your Default"
context.set("topic", value);

```

1. then in `On Message`

```auto
context.get("topic") // what was provided as an `env` or you chosen default (as decided in On Start)

```

---

<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:** [6 January 2024 21:46 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/6 "2024-01-06T21:46:23Z")

</div>

Close.

It isn't I **CAN'T** but more as a catch if I don't set it.

The problem - as I now see it - is that I have specified the `env.topic` as a `STRING` in the `subflow`.  
Alas that means it can't be `null` or `undefined`.

So I need to catch the _problem_ if the `length` is `<1` (or `0`)

Does that help?

---

<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:** [6 January 2024 21:50 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/7 "2024-01-06T21:50:23Z")

</div>

in `on start,` (or at any point) you can check its `undefined` state.

```auto

if(!env.get("topic")){
    node.error("Not Set")
}

```

a blank string is considered `falsely`

 ![Screenshot 2024-01-06 at 21.50.02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8b0a2129ade2e5a73c113041eb7061c7af20799b.png)

---

<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:** [6 January 2024 21:53 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/8 "2024-01-06T21:53:26Z")

</div>

Yes, but as I just said: It isn't saying `NOT SET`.  
It is simply giving me an empty string.

So I need to detect if the length is `<1` (to say)

As I don't know - off the back of my hand - the command to do this I am really stuck.  
I am trying to look, but I am not getting results that help me as they are pure JS code and when I try to enter it in the `function` node, it errors.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [6 January 2024 21:57 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/9 "2024-01-06T21:57:39Z")

</div>

This?

```js
if ("".length < 1) {}

```

I didn't understand the whole point 🤔

---

<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:** [6 January 2024 21:58 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/10 "2024-01-06T21:58:23Z")

</div>

you can do it `on message` also (no need for `context`)

```auto
if(!env.get("topic")){
   throw new Error("Topic not set")
}

```

---

<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:** [6 January 2024 22:02 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/11 "2024-01-06T22:02:05Z")

</div>

(Nor do I - to be honest)

I wrote a subflow and didn't do my homework.

I didn't set one of the values and it worked only by luck.

I found ANOTHER problem with the subflow and am fixing all the problems - I hope.

So I need to catch any undefined `env` names and set them to _something_.

But I can't _talk the talk_ of `JS` and so despite my searches can't find the command/trick to detect the unset value.  
Partly because if you specify a `TYPE` for the `env` you don't get a `null` or `undefined` when you check it.

This is what I have now and I think it works.  
(am about to test it)

```auto
// Code added here will be run once
// whenever the node is started.
let value = env.get("topic")
if (value.length < 1)
{
    value = "DEFAULT";
    node.warn("CAUGHT")
}
context.set("topic", value);

```

I put the `node.warn` in there to indicate it is catching it and it seems to be doing that.

I'll get back to this in a few seconds.

---

<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:** [6 January 2024 22:05 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/12 "2024-01-06T22:05:58Z")

</div>

Ok, only to stop the older posts being edited:

What I now have works.

Code:  
`on start`

```auto
// Code added here will be run once
// whenever the node is started.
let value = env.get("topic")
if (value.length < 1)
{
    value = "DEFAULT";
    node.warn("CAUGHT")
}
node.warn("Value being set " + value)
context.set("topic", value);

```

and in the main code, I set the `msg.topic` to `context.get("topic")` and I get the right topic out.

---

<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:** [6 January 2024 22:08 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/14 "2024-01-06T22:08:01Z")

</div>

ignore that 😆

---

<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:** [6 January 2024 22:08 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/15 "2024-01-06T22:08:28Z")

</div>

I wasn't quick enough to see what you said there. 😉

No problems.

Ah, just saw your next post.

All good.

So to get a second set of eyes on it:

That will work - yes?

---

<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:** [6 January 2024 22:11 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/16 "2024-01-06T22:11:26Z")

</div>

Just to share the new subflow:

```auto
[{"id":"5b2f1c1e34d60f19","type":"subflow","name":"3 Press button","info":"2024 01 07\n==\n\nHuge bug found and fixed.\n\nStill have a bug with code if the\n`topic` is not set.\n\nBut now better than what it was.","category":"","in":[{"x":70,"y":190,"wires":[{"id":"ec5080f153f43d22"}]}],"out":[{"x":840,"y":190,"wires":[{"id":"ee1c20a8875e36cc","port":0}]},{"x":840,"y":270,"wires":[{"id":"10d2bd1bfc555db3","port":0}]}],"env":[{"name":"startat","type":"num","value":"","ui":{"label":{"en-US":"start at"},"type":"input","opts":{"types":["num"]}}},{"name":"hold","type":"bool","value":"true","ui":{"type":"input","opts":{"types":["bool"]}}},{"name":"topic","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"Message 1","type":"str","value":""},{"name":"Message 2","type":"str","value":""},{"name":"Message 3","type":"str","value":""},{"name":"colour 1","type":"str","value":""},{"name":"colour 2","type":"str","value":""},{"name":"colour 3","type":"str","value":""},{"name":"fontclr 1","type":"str","value":""},{"name":"fontclr 2","type":"str","value":""},{"name":"fontclr 3","type":"str","value":""}],"meta":{},"color":"#DDAA99","inputLabels":["Input"],"outputLabels":["Output","Loop back to button node"],"icon":"node-red-dashboard/ui_button.png"},{"id":"9c628490f5a7ab36","type":"switch","z":"5b2f1c1e34d60f19","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":230,"y":270,"wires":[["625edd1859414ac8"],["2ed89392aefd3ac3"],["75984bf53702c1ac"]]},{"id":"625edd1859414ac8","type":"change","z":"5b2f1c1e34d60f19","name":"1","rules":[{"t":"set","p":"text","pt":"msg","to":"Message 1","tot":"env"},{"t":"set","p":"bgc","pt":"msg","to":"colour 1","tot":"env"},{"t":"set","p":"fontclr","pt":"msg","to":"fontclr 1","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":230,"wires":[["10d2bd1bfc555db3"]]},{"id":"2ed89392aefd3ac3","type":"change","z":"5b2f1c1e34d60f19","name":"2","rules":[{"t":"set","p":"text","pt":"msg","to":"Message 2","tot":"env"},{"t":"set","p":"bgc","pt":"msg","to":"colour 2","tot":"env"},{"t":"set","p":"fontclr","pt":"msg","to":"fontclr 2","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":270,"wires":[["10d2bd1bfc555db3"]]},{"id":"75984bf53702c1ac","type":"change","z":"5b2f1c1e34d60f19","name":"3","rules":[{"t":"set","p":"text","pt":"msg","to":"Message 3","tot":"env"},{"t":"set","p":"bgc","pt":"msg","to":"colour 3","tot":"env"},{"t":"set","p":"fontclr","pt":"msg","to":"fontclr 3","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":310,"wires":[["10d2bd1bfc555db3"]]},{"id":"ec5080f153f43d22","type":"function","z":"5b2f1c1e34d60f19","name":"","func":"// Get \"start value\"\nif (msg.topic == \"startup\")\n{\n context.set(\"previous\",msg.payload-1);\n}\n\nif (msg.payload == \"reset\")\n{\n context.set(\"previous\",0);\n return;\n}\n\nvar max = 4;\nvar previous = context.get(\"previous\") || 0;\nprevious = (previous + 1) % max;\ncontext.set(\"previous\",previous);\n\nif (previous == 0)\n{\n previous = 1;\n context.set(\"previous\",1);\n}\nmsg.payload = previous;\nmsg.topic = context.get(\"topic\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\nlet value = env.get(\"topic\")\nif (value.length < 1)\n{\n value = \"DEFAULT\";\n}\ncontext.set(\"topic\", value);\n","finalize":"","libs":[],"x":390,"y":190,"wires":[["9c628490f5a7ab36","ee1c20a8875e36cc"]]},{"id":"ee1c20a8875e36cc","type":"trigger","z":"5b2f1c1e34d60f19","name":"Delay","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"350","extend":true,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":190,"wires":[["20347974efa46acb"]]},{"id":"20347974efa46acb","type":"change","z":"5b2f1c1e34d60f19","name":"$hold","rules":[{"t":"set","p":"hold","pt":"msg","to":"hold","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":535,"y":150,"wires":[["52f023f6a52afa5b"]],"l":false},{"id":"52f023f6a52afa5b","type":"switch","z":"5b2f1c1e34d60f19","name":"if FALSE","property":"hold","propertyType":"msg","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":585,"y":150,"wires":[["7d8c55ef2950c72a"]],"l":false},{"id":"7d8c55ef2950c72a","type":"change","z":"5b2f1c1e34d60f19","name":"reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":635,"y":150,"wires":[["ec5080f153f43d22"]],"l":false},{"id":"10d2bd1bfc555db3","type":"junction","z":"5b2f1c1e34d60f19","x":550,"y":270,"wires":[[]]},{"id":"d87556ee78f63d9c","type":"subflow:5b2f1c1e34d60f19","z":"88de1ac2.8b8c38","name":"","env":[{"name":"startat","value":"0","type":"num"},{"name":"topic","value":"somethingelse","type":"str"},{"name":"Message 1","value":"ALL","type":"str"},{"name":"Message 2","value":"BLOCK","type":"str"},{"name":"Message 3","value":"ONE","type":"str"},{"name":"colour 1","value":"limegreen","type":"str"},{"name":"colour 2","value":"violet","type":"str"},{"name":"colour 3","value":"fuchsia","type":"str"},{"name":"fontclr 1","value":"black","type":"str"},{"name":"fontclr 2","value":"black","type":"str"},{"name":"fontclr 3","value":"black","type":"str"}],"x":1640,"y":280,"wires":[["e20a43ccb6ec319a"],[]]}]

```

This works - if you don't mind checking.

---

<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:** [6 January 2024 22:13 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/17 "2024-01-06T22:13:03Z")

</div>

This is where I was going.

```auto
const getValue = () => {
    if (env.get("topic")) {
            return env.get("topic");
        } else {
            node.warn("Using Default")
            return "DEFAULT"
        }
    }
}

context.set("topic", getValue());

```

---

<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:** [6 January 2024 22:16 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/18 "2024-01-06T22:16:38Z")

</div>

Sorry but

```auto
const getValue = () => {
    if (env.get("topic") {
            return env.get("topic");
        } else {
            node.warn("Using Default")
            return "DEFAULT"
        }
    }
}

context.set("topic", getValue());

```

Is above me.

and I am also confused by it being a `const`......  
(What can I say? I never really dealt with this kind of language or structure in my life. This is still at the coal face for me.)

Does that go in the `at start` tab?

(Now wanting to step on your toes while you are replying but...)  
Isn't this easier?

```auto
// Code added here will be run once
// whenever the node is started.
let value = env.get("topic")
if (value.length < 1)
{
    value = "DEFAULT";
}
context.set("topic", value);

```

---

<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:** [6 January 2024 22:18 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/19 "2024-01-06T22:18:07Z")

</div>

> [@Trying\_to\_learn](#):
>
> Does that go in the `at start` tab?

Correct.

The `const` is an [arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)

that returns your env or your default

---

<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:** [6 January 2024 22:18 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/20 "2024-01-06T22:18:54Z")

</div>

Again: _an arrow function_.

WAY over my head of knowledge.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [6 January 2024 22:20 UTC](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353/21 "2024-01-06T22:20:23Z")

</div>

Not sure what I'm going to say but if you want to add (because you forgot) a value to env.topic why not do it directly in the subflow def?

```json
{
  "name": "topic",
  "type": "str",
  "value": "",
  "ui": {
    "type": "input",
    "opts": {
      "types": [
        "str"
      ]
    }
  }
}

```

[Next page](https://discourse.nodered.org/t/on-start-tab-confused-how-to-use/84353.md?page=2)
