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

**URL:** <https://discourse.nodered.org/t/invalid-properties-error-in-javascript-code-in-function-node-but-function-works/86571>\
**Category:** General\
**Created:** [19 March 2024 18:12 UTC](https://discourse.nodered.org/t/invalid-properties-error-in-javascript-code-in-function-node-but-function-works/86571 "2024-03-19T18:12:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stephenn/32/66644_2.png) [@stephenn](https://discourse.nodered.org/u/stephenn)\
**Post date:** [19 March 2024 18:12 UTC](https://discourse.nodered.org/t/invalid-properties-error-in-javascript-code-in-function-node-but-function-works/86571/1 "2024-03-19T18:12:07Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 March 2024 18:26 UTC](https://discourse.nodered.org/t/invalid-properties-error-in-javascript-code-in-function-node-but-function-works/86571/2 "2024-03-19T18:26:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 March 2024 18:33 UTC](https://discourse.nodered.org/t/invalid-properties-error-in-javascript-code-in-function-node-but-function-works/86571/3 "2024-03-19T18:33:50Z")

</div>

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

> [@stephenn](#):
>
> ```auto
> var currentT = Number(flow.get("current1stFloorSP"));
> node.warn("currentT: " + currentT);
> const newmsg = { 
> payload: { 
> data: { 
> "temperature": currentT 
> }
> } 
> };
> return newmsg;
> 
> ```

---

<div class="post-metadata">

**Author:** ![stephenn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stephenn/32/66644_2.png) [@stephenn](https://discourse.nodered.org/u/stephenn)\
**Post date:** [19 March 2024 18:48 UTC](https://discourse.nodered.org/t/invalid-properties-error-in-javascript-code-in-function-node-but-function-works/86571/4 "2024-03-19T18:48:55Z")

</div>

> [@E1cid](#):
>
> which will still work but is poor JS coding

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

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 March 2024 18:56 UTC](https://discourse.nodered.org/t/invalid-properties-error-in-javascript-code-in-function-node-but-function-works/86571/5 "2024-03-19T18:56:30Z")

</div>

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

 ![Screenshot_20240319-185510](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/880d8210cacfe9f2fe5c4bf8f20453d9dde07709.png)

---

<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:** [17 June 2024 18:57 UTC](https://discourse.nodered.org/t/invalid-properties-error-in-javascript-code-in-function-node-but-function-works/86571/6 "2024-06-17T18:57:02Z")

</div>

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