"Invalid properties: Error in JavaScript Code" in Function Node but Function works

I am trying to use a Function Node to pull a stored temperature value and format it so that I can send it to a Call Service Node in Home Assistant. This code works just as I want. However, the Function Node has a Red Triangle and the error says "Invalid properties: Error in JavaScript Code". Then, I have to deal with the warning every time I deploy

Any ideas? I am sure it is something simple. I rarely, if ever, use function nodes so I am a newbie with them.

var currentT = Number(flow.get("current1stFloorSP"));
node.warn("currentT: " + currentT);
newmsg = { 
    payload: { 
        data: { 
            "temperature": currentT 
        }
    } 
};
return newmsg;

You have not declared newmsg, which will still work but is poor JS coding.

If you are using monaco editor, then the red undulating underlining should have given you a clue.

As @E1cid suggested, you need to declare 'newmsg'.
Try this... and see if the red triangle goes away.

I am sure that I do a lot of that w/ my limited knowledge of it. :grin:

Adding const worked. Thank you both. I knew it was something simple.

If you use the error checking of the editor, it shows error and gives suggestions

1 Like

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