# Get global value when setting payload

**URL:** <https://discourse.nodered.org/t/get-global-value-when-setting-payload/8733>\
**Category:** General\
**Created:** [8 March 2019 06:53 UTC](https://discourse.nodered.org/t/get-global-value-when-setting-payload/8733 "2019-03-08T06:53:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![waqaslam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/waqaslam/32/2271_2.png) [@waqaslam](https://discourse.nodered.org/u/waqaslam)\
**Post date:** [8 March 2019 06:53 UTC](https://discourse.nodered.org/t/get-global-value-when-setting-payload/8733/1 "2019-03-08T06:53:03Z")

</div>

Hi  
Is there a way to retrieve global variable's value when setting a payload for a node?  
Lets say, in below image, I want to set the UUID hex-value coming from global-context in dashboard-button's payload option when building a command:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/ab0ab08d35b6c36ae45e06e04daadb68191cb694.png)

Currently I can do the following:

- Change the payload type to **global.** and reference the variable - but will only give variable's value
- Add a **function** node to build the command together with variable's value

But i'm looking for an inline approach - if possible?

Thanks

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [8 March 2019 08:32 UTC](https://discourse.nodered.org/t/get-global-value-when-setting-payload/8733/2 "2019-03-08T08:32:46Z")

</div>

You can use the change node, probably easiest using JSONata as this can access both the incoming msg properties, global variables and can construct strings.

---

<div class="post-metadata">

**Author:** ![waqaslam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/waqaslam/32/2271_2.png) [@waqaslam](https://discourse.nodered.org/u/waqaslam)\
**Post date:** [8 March 2019 09:07 UTC](https://discourse.nodered.org/t/get-global-value-when-setting-payload/8733/3 "2019-03-08T09:07:07Z")

</div>

Lets say I use **Inject** node , so how can I use global-context when selecting payload type to JSON?  
or are you saying I should use **Change** node to search and replace?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [8 March 2019 09:08 UTC](https://discourse.nodered.org/t/get-global-value-when-setting-payload/8733/4 "2019-03-08T09:08:34Z")

</div>

Have you looked at what the change node can do? You don't want to do s/r since that is static and you want to combine data - you need JSONata for that.

---

<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:** [8 March 2019 09:30 UTC](https://discourse.nodered.org/t/get-global-value-when-setting-payload/8733/5 "2019-03-08T09:30:43Z")

</div>

Hi @waqaslam

The Inject node doesn't support the Expression type, so you'd need to use a Change node.

You can then use the JSONata expression:

```auto
'sudo smartctl -A /dev/disk/by-uuid/' & $globalContext('my-uuid') & ' | awk "NR>6" '

```

Note that JSONata uses `&` to join strings.
