# How to can i store msg.payload in node red

**URL:** https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743
**Category:** General
**Created:** [11 September 2020 12:04 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743 "2020-09-11T12:04:35Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 12:04 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/1 "2020-09-11T12:04:35Z")

</div>

how to can i store msg.payload in node red

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [11 September 2020 12:12 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/2 "2020-09-11T12:12:24Z")

</div>

Hi, if you want a sensible answer, I would suggest you provide additional info. E.g...

- Where you want to store msg.payload?
- What is inside msg.payload?

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 12:17 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/3 "2020-09-11T12:17:19Z")

</div>

1)i want to msg.payload to store in a variable and then after wards i will be using that var to Subcriber Topic.  
2) msg.payload has user input string.(CR\_SUCCESS).

 ![r](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/48cec4d84d85e3daff5606792e6e530be771038d.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [11 September 2020 12:24 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/4 "2020-09-11T12:24:34Z")

</div>

> [@shipra](#):
>
> i want to msg.payload to store in a variable

You can store msg.payload in a var in a function node like this...

```auto
var my_var = msg.payload;

```

> [@shipra](#):
>
> after wards i will be using that var to Subcriber Topic

I assume you mean subscribe an MQTT topic? You cannot dynamically subscribe to an MQTT topic.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 12:26 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/5 "2020-09-11T12:26:56Z")

</div>

yes sir i have a gateway code where sub call is there.

> [@Steve-Mcl](#):
>
> I assume you mean subscribe an MQTT topic? You cannot dynamically subscribe to an MQTT topic.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 12:34 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/6 "2020-09-11T12:34:12Z")

</div>

sir.in my code one user case is there where i am publishing twice on a topic (FOB ID and TAG ID).  
what is solved:

1. individual cases of both ID are working i.e if entered id is in my DB then print CR\_SUCCESS to the SUB Topic otherwise CR\_FAIL.  
what not working:
2. 3rd case is not working i.e i am taking 2 inputs one is FOB and other is TAG and similarly match both simultaneously with my DB and Print statement to SUB.  
where the problem coming:
3. as i am entering FOB ,then msg.payload is storing CR\_SUCCESS(suppose user entered right ID)but as soon as i am entering TAG again it is showing me CR\_SUCCESS(suppose i entered wrong TAG ).why???

---

<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: [11 September 2020 12:40 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/7 "2020-09-11T12:40:52Z")

</div>

I have remembered you were asking about this same project a couple months ago here: [Copying my Door control status back to my Mysql databse](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383)

You also have this thread from earlier today: [How to calculate 2 msg.id coming from 2 pub different topics simulataneously](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730)

If you have two separate messages arriving from MQTT nodes and you need to compare them, you need to get both values into a single message. I pointed you at a recipe for doing that here: [How to calculate 2 msg.id coming from 2 pub different topics simulataneously](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/2)

It is not clear if you have tried anything we have suggested. If there is something you are not sure about, please ask - but please read the material we point you at first.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 13:35 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/8 "2020-09-11T13:35:41Z")

</div>

Sir thank you answering this,but sir in this task 1 ) and 2) is completed only 3)is remaining.please suggest?

---

<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: [11 September 2020 13:54 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/9 "2020-09-11T13:54:02Z")

</div>

> [@shipra](#):
>
> why???

That is impossible for us to say as you have not shared any specific details of your application.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 18:57 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/12 "2020-09-11T18:57:06Z")

</div>

Thank you sir,for your help,it means alot for me  
Now the output is coming as required.

---

<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: [10 November 2020 18:57 UTC](https://discourse.nodered.org/t/how-to-can-i-store-msg-payload-in-node-red/32743/13 "2020-11-10T18:57:19Z")

</div>

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