# Msg.payload : undefined message

**URL:** <https://discourse.nodered.org/t/msg-payload-undefined-message/76234>\
**Category:** General\
**Created:** [7 March 2023 14:01 UTC](https://discourse.nodered.org/t/msg-payload-undefined-message/76234 "2023-03-07T14:01:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alveron](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@alveron](https://discourse.nodered.org/u/alveron)\
**Post date:** [7 March 2023 14:01 UTC](https://discourse.nodered.org/t/msg-payload-undefined-message/76234/1 "2023-03-07T14:01:03Z")

</div>

Thanks in advance,  
Here is a snippet of a flow I am working with (newbie to node-red)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe0112dd9794f5eb78e789217fa5a5eadac81bdf.png)

here is the function code I am using

```auto
var newMsg = {
    "topic": "INSERT INTO SENSORDATA VALUES ( " + msg.payload.time + ", " + msg.payload.id + ", " + msg.payload.type + ", " + msg.payload.data + ")"
}
return newMsg;

```

Here are the debug messages

```auto
3/5/2023, 10:42:13 PMnode: debug 5
fdrs/data : msg.payload : Object
{ id: 1, type: 1, data: 22.06900024, time: 49534 }
3/5/2023, 10:42:13 PMnode: debug 7
INSERT INTO SENSORDATA VALUES ( 49534, 1, 3, 53) : msg.payload : undefined
undefined

```

My question is why do I have the msg.payload undefined error? The data seems to have been transferred correctly, so I am not sure what the problem is?

---

<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:** [7 March 2023 14:12 UTC](https://discourse.nodered.org/t/msg-payload-undefined-message/76234/2 "2023-03-07T14:12:30Z")

</div>

You create a new msg with newMsg. You add topic to it and nothing else. Then you return it and there is no payload, because you never added it.  
Try adding it, e.g.

```auto
var newMsg = {
    "topic": "INSERT INTO SENSORDATA VALUES ( " + msg.payload.time + ", " + msg.payload.id + ", " + msg.payload.type + ", " + msg.payload.data + ")"
}
newMsg.payload = msg.payload;

return newMsg;

```

Or using OG msg

```auto
msg.topic = {
    "topic": "INSERT INTO SENSORDATA VALUES ( " + msg.payload.time + ", " + msg.payload.id + ", " + msg.payload.type + ", " + msg.payload.data + ")"
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![alveron](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@alveron](https://discourse.nodered.org/u/alveron)\
**Post date:** [7 March 2023 16:46 UTC](https://discourse.nodered.org/t/msg-payload-undefined-message/76234/3 "2023-03-07T16:46:38Z")

</div>

Thanks, sorry I was under the mistaken impression that the returned msg always became the payload msg.

---

<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:** [6 May 2023 16:46 UTC](https://discourse.nodered.org/t/msg-payload-undefined-message/76234/4 "2023-05-06T16:46:54Z")

</div>

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