# Insert flow variables in message payloads

**URL:** <https://discourse.nodered.org/t/insert-flow-variables-in-message-payloads/47097>\
**Category:** General\
**Created:** [13 June 2021 11:44 UTC](https://discourse.nodered.org/t/insert-flow-variables-in-message-payloads/47097 "2021-06-13T11:44:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [13 June 2021 11:44 UTC](https://discourse.nodered.org/t/insert-flow-variables-in-message-payloads/47097/1 "2021-06-13T11:44:51Z")

</div>

Hi everyone,  
here comes another easy challenge for the Node-Red pros among you 😄 Following situation: Based on a certain trigger, I would like to send a message payload to an Alexa node that contains data from some flow variables I defined.

Here is my example for the msg.payload I would like to create from a change node using the JSONata editor:

`"Outside temperature is about "& flow.get("OutsideTemp") &" degrees at "& flow.get("Humidity") &" % humidity"`

Unfortunately, the variables get simply ignored when creating the actual object. Now tell me what´s the trick to integrate flow variables into messages 🧙

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [13 June 2021 12:03 UTC](https://discourse.nodered.org/t/insert-flow-variables-in-message-payloads/47097/2 "2021-06-13T12:03:08Z")

</div>

I will do this myself in a function node.  
In a function node you concatenate strings with a **+** instead **&**.

```auto
msg.payload= "Outside temperature is about "+ flow.get("OutsideTemp") +" degrees at "+ flow.get("Humidity") +" % humidity"
return msg

```

---

<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:** [13 June 2021 12:48 UTC](https://discourse.nodered.org/t/insert-flow-variables-in-message-payloads/47097/3 "2021-06-13T12:48:14Z")

</div>

In JSONata expression it would be `$flowContext("OutsideTemp")` not flow.get

---

<div class="post-metadata">

**Author:** ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)\
**Post date:** [13 June 2021 13:12 UTC](https://discourse.nodered.org/t/insert-flow-variables-in-message-payloads/47097/4 "2021-06-13T13:12:36Z")

</div>

Beautiful 😃 Thanks both @edje11 & @E1cid for the quick response!

---

<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:** [13 June 2021 13:22 UTC](https://discourse.nodered.org/t/insert-flow-variables-in-message-payloads/47097/5 "2021-06-13T13:22:00Z")

</div>

Here's a picture of my flow to get a report on my Raspberry Pi.

 ![Screen Shot 06-12-21 at 09.38 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/1168cc5e798d9207e4701393dc25e9b7c052427c.jpeg)  
And here's what 'Format response' looks like using Javascript...  
 ![Screen Shot 06-13-21 at 02.18 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b85a85c6d29e39ade4fcaa7939e9718917e061b.jpeg)

---

<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:** [27 June 2021 13:22 UTC](https://discourse.nodered.org/t/insert-flow-variables-in-message-payloads/47097/6 "2021-06-27T13:22:09Z")

</div>

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