Help with error in function node

I am working on a project - top secret just now. :wink:

This is the code in the function node.

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.

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

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

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

1 Like

Thanks.

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

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

Silly me.

Thanks.

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