# Help with error in function node

**URL:** <https://discourse.nodered.org/t/help-with-error-in-function-node/40534>\
**Category:** General\
**Created:** [7 February 2021 06:17 UTC](https://discourse.nodered.org/t/help-with-error-in-function-node/40534 "2021-02-07T06:17:55Z")\
**Posts on this page:** 6\
**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:** [7 February 2021 06:17 UTC](https://discourse.nodered.org/t/help-with-error-in-function-node/40534/1 "2021-02-07T06:17:56Z")

</div>

I am working on a project - _top secret_ just now. 😉

This is the code in the `function` node.

```auto
let j = flow.get("StartMsg");
if (j == undefined)
{
    j = "Start message";
}
msg.payload = j;
if (flow.get("PassThrough" == true))
{
    msg.payload = flow.get("SavedMessage");
}
return msg;

```

But it throws up this error:

`TypeError: key.startsWith is not a function`

Where is this happening?

I don't get it. Sorry.

It is the last condition that is doing it.

`if (flow.get("PassThrough" == true))` that is causing it to the best of my knowledge.

---

<div class="post-metadata">

**Author:** ![dathor](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dathor](https://discourse.nodered.org/u/dathor)\
**Post date:** [7 February 2021 07:27 UTC](https://discourse.nodered.org/t/help-with-error-in-function-node/40534/2 "2021-02-07T07:27:57Z")

</div>

how about you refactor that to something like this...

```auto
if (flow.get("PassThrough")){
  msg.payload = flow.get("SavedMessage")
} else {
  msg.payload = flow.get("StartMsg") || "Start Messsage"
}
```

---

<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:** [7 February 2021 07:30 UTC](https://discourse.nodered.org/t/help-with-error-in-function-node/40534/3 "2021-02-07T07:30:40Z")

</div>

You have the parentheses in the wrong place, you have `== true` inside the `flow.get()`

---

<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:** [7 February 2021 07:31 UTC](https://discourse.nodered.org/t/help-with-error-in-function-node/40534/4 "2021-02-07T07:31:04Z")

</div>

Thanks.

But I am not _confident_ enough to do those sort of tricks.

And: It doesn't tell me why that error was happening.

---

<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:** [7 February 2021 07:31 UTC](https://discourse.nodered.org/t/help-with-error-in-function-node/40534/5 "2021-02-07T07:31:41Z")

</div>

Silly me.

Thanks.

---

<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:** [21 February 2021 07:31 UTC](https://discourse.nodered.org/t/help-with-error-in-function-node/40534/6 "2021-02-21T07:31:43Z")

</div>

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