# How to inject msg.payload.value as msg.id to function node?

**URL:** <https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627>\
**Category:** General\
**Created:** [28 May 2019 08:40 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627 "2019-05-28T08:40:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![muharremsari](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muharremsari/32/7996_2.png) [@muharremsari](https://discourse.nodered.org/u/muharremsari)\
**Post date:** [28 May 2019 08:40 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/1 "2019-05-28T08:40:09Z")

</div>

```auto
[{"id":"9d466ec1.7ecb6","type":"function","z":"e50cdc2d.57d62","name":"inputsource msg.id or msg.name","func":"var lookups = flow.get(\"lookups\");\nif(msg.id){\n msg.payload = lookups.id2name[msg.id]; \n return msg;\n}\nif(msg.name){\n msg.payload = lookups.name2id[msg.name]; \n return msg;\n}\nif(msg.topic == \"id\"){\n msg.payload = lookups.id2name[msg.payload];\n return msg;\n}\nif(msg.topic == \"name\"){\n msg.payload = lookups.name2id[msg.payload]; \n return msg;\n}\nnode.warn(`msg doesnt contain id or name - or - topic is not set to id or msg`);","outputs":1,"noerr":0,"x":1346.25,"y":287.4999694824219,"wires":[["9cae58f6.361018","c4c7b797.644d58"]]},{"id":"81530402.0a7288","type":"change","z":"e50cdc2d.57d62","name":"","rules":[{"t":"set","p":"payload.value","pt":"msg","to":"id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1064.5,"y":287,"wires":[["9d466ec1.7ecb6","dbe55466.798bf8"]]},{"id":"ce64d661.b39858","type":"function","z":"e50cdc2d.57d62","name":"UPS INPUT SOURCE","func":"msg.payload = msg.payload [0].value\nreturn msg;","outputs":1,"noerr":0,"x":798.5,"y":289,"wires":[["81530402.0a7288"]]},{"id":"a1810a8c.ae14f8","type":"json","z":"e50cdc2d.57d62","name":"","property":"payload","action":"obj","pretty":false,"x":556.5,"y":290,"wires":[["ce64d661.b39858"]]},{"id":"5f255d09.fb30c4","type":"snmp walker","z":"e50cdc2d.57d62","host":"10.67.20.28","community":"public","version":"1","oids":"1.3.6.1.4.1.534.1.3.5","timeout":5,"name":"CMUPS","x":304.5,"y":289,"wires":[["a1810a8c.ae14f8"]]},{"id":"4127aefb.3957e","type":"inject","z":"e50cdc2d.57d62","name":"","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":177,"wires":[["89a692d6.e63dd","5f255d09.fb30c4","c70a4f52.183ea","f8e9890b.cba208"]]}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 May 2019 08:44 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/2 "2019-05-28T08:44:05Z")

</div>

You'll need to explain a lot more about what you are asking. Just pasting a flow doesn't help.

---

<div class="post-metadata">

**Author:** ![muharremsari](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muharremsari/32/7996_2.png) [@muharremsari](https://discourse.nodered.org/u/muharremsari)\
**Post date:** [28 May 2019 09:04 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/3 "2019-05-28T09:04:09Z")

</div>

Excuse me. U r right.

I have a lookup table for meaning message. I was tested SAMPLE with inject node. It's ok.

But sample inject node have a TOPIC cell. It was set ID.

How do i change msg.payload to msg.id.

Thanks

 ![msg_id](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/579ec6865d7d803ac9f8711b5e7823d1e3da69f7.jpeg)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 May 2019 09:04 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/4 "2019-05-28T09:04:50Z")

</div>

> [@muharremsari](#):
>
> How do i change msg.payload to msg.id.

Use a Change node

---

<div class="post-metadata">

**Author:** ![muharremsari](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muharremsari/32/7996_2.png) [@muharremsari](https://discourse.nodered.org/u/muharremsari)\
**Post date:** [28 May 2019 09:11 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/5 "2019-05-28T09:11:41Z")

</div>

I was use change node on my flow. But i recieve "msg doesnt contain id or name - or - topic is not set to id or msg"

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 May 2019 09:26 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/6 "2019-05-28T09:26:06Z")

</div>

From your screen shot, you have the Change configured to set the property `msg.payload.value` with the value of `msg.id`. I think you mean to do the opposite - you want to set `msg.id` to the value of `msg.payload.value`.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 May 2019 09:32 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/7 "2019-05-28T09:32:45Z")

</div>

(1) your msg does not contain `msg.id` - add some debugs displaying the complete msg object.  
(2) you cannot change msg.payload property from a string/number to an object just by adding another label to it like msg.payload.value - msg.payload needs to be an `object` or you maybe able to use jsonata in the change node to make msg.payload and object.  
(3) Are you looking to to use `_msgid`?

---

<div class="post-metadata">

**Author:** ![muharremsari](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muharremsari/32/7996_2.png) [@muharremsari](https://discourse.nodered.org/u/muharremsari)\
**Post date:** [28 May 2019 09:42 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/8 "2019-05-28T09:42:58Z")

</div>

> [@zenofmud](#):
>
> Are you looking to to use

Yes i would use \_msgid

---

<div class="post-metadata">

**Author:** ![muharremsari](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muharremsari/32/7996_2.png) [@muharremsari](https://discourse.nodered.org/u/muharremsari)\
**Post date:** [28 May 2019 09:46 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/10 "2019-05-28T09:46:56Z")

</div>

It has not changed

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 May 2019 10:32 UTC](https://discourse.nodered.org/t/how-to-inject-msg-payload-value-as-msg-id-to-function-node/11627/11 "2019-05-28T10:32:59Z")

</div>

> [@zenofmud](#):
>
> (2) you can change msg.payload property from a string/number to an object just by adding another label to it like msg.payload.value - msg.payload needs to be an `object` or you will need to use jsonata in

I made an error, when I said:

> 'you `can` change msg.payload property from a string/number to an object just by adding another label to it like msg.payload.value'

I ment to write:

> 'you `cannot` change msg.payload property from a string/number to an object just by adding another label to it like msg.payload.value'

I have edited the original post to correct it.
