# How to get global variable properties

**URL:** <https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340>\
**Category:** General\
**Created:** [23 March 2019 00:54 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340 "2019-03-23T00:54:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [23 March 2019 00:54 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/1 "2019-03-23T00:54:40Z")

</div>

Hi guys, I working on my device and I have doubts how to working with context global variable object properties. You can see bellow my global context variable:

**My global variable object and properties**  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/161d41f750572c363722c8f1e83287a9b22519a4.png)

I was use this function code to get object property storage on global variable, but I don´t know how to read for example, the property **nwk\_addr** and the value storage (528b).

```auto
 var ext_addr = global.get ("00137a0000009a99");
 msg.payload = ext_addr;
 return msg;

```

When I using the unique id (ext\_addr = 00137a0000009a99) I receiving all properties, as you can see bellow. How to I can filter only one specific property for each unique id?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/dc8f1d64b3c587d36527e7386ace090dd8ee8829.png)

Someone can help me, please?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [23 March 2019 05:05 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/2 "2019-03-23T05:05:14Z")

</div>

How did you set the global variable ?

`global.set("device",value/object)`

For your question:

`msg.payload = ext_addr.payload.properties.ModelID`

note that when you hover your mouse behind the properties you see 2 icons; the first is: copy path, this you can use to eliminate writing the path yourself.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [23 March 2019 07:26 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/3 "2019-03-23T07:26:42Z")

</div>

As @bakman2 suggests the debug window can help you here.  
There’s a page in the docs “working with messages” that’s worth a read.

How to navigate javascript objects is very important one Node-RED so it is also worth working through one of the many tutorials you will find online

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [23 March 2019 10:50 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/4 "2019-03-23T10:50:46Z")

</div>

Hi bakman2 thanks a lot. I got success after you advise me how to do it!

**I set it up like this:**

```auto
 global.set(unique,
 {"ext_addr":unique,
 "properties":properties}, "memoryOnly");

```

**I used:**

```auto
 var ext_addr = global.get("00137a0000009a99");
 msg.payload = ext_addr.properties.nwk_addr;
 return msg;

```

Thanks a lot!  
Best Regards,  
Alex

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [23 March 2019 10:54 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/5 "2019-03-23T10:54:43Z")

</div>

Hi ukmoose,  
I read this page, but I could not develop well after that.

Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [25 March 2019 12:02 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/6 "2019-03-25T12:02:52Z")

</div>

Hi Guys, I working very well using a global variable in the memory, but i found problem in those variables after rpi3 reboot, the object properties disappeared (undefined) as can see below:

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

**I storage it in the memory using this code:**

```auto
  var unique = String(msg.payload.name);
    var Epcount = global.get('EP_Count');
    var prop1 = global.get('nwk_addr1');
    var prop2 = global.get('nwk_addr2');
    var prop3 = global.get('ZDP_EP1');
    var prop4 = global.get('ZDP_EP2');
    var prop5 = global.get('attr.str');
    var prop6 = global.get('ext_addr1');
    var prop7 = global.get('ext_addr2');
    var prop8 = global.get('ext_addr3');
    var prop9 = global.get('ext_addr4');
    var prop10 = global.get('ext_addr5');
    var prop11 = global.get('ext_addr6');
    var prop12 = global.get('ext_addr7');
    var prop13 = global.get('ext_addr8');

if (Epcount ==1) {
    
        switch (prop5) {
    
            case 'ZBHT-2':{
                    var properties = {
                    "nwk_addr": prop1+prop2,
                    "nwk_addrb1":prop1, 
                    "nwk_addrb2":prop2, 
                    "EP1":prop3,
                    "ModelID":prop5,
                    "Ext_addrb1":prop6,
                    "Ext_addrb2":prop7,
                    "Ext_addrb3":prop8,
                    "Ext_addrb4":prop9,
                    "Ext_addrb5":prop10,
                    "Ext_addrb6":prop11,
                    "Ext_addrb7":prop12,
                    "Ext_addrb8":prop13,
                    "Type":"Netvox Thermometer"
                    };

```

Someone have idea how to fix it?

Best Regards,  
Alex

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [25 March 2019 12:35 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/7 "2019-03-25T12:35:02Z")

</div>

show us how you are setting the variables rather than getting them.

You will see that some are listed as “memory only” which is why they disappear on restart (as described in the docs)

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [25 March 2019 13:44 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/8 "2019-03-25T13:44:23Z")

</div>

Hi unkmosse, thanks!  
do you can share with me a doc or article to explain how to get global variable in the file, similar i did in the memory?

Best Regards,  
Alex

---

<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:** [25 March 2019 15:51 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/9 "2019-03-25T15:51:33Z")

</div>

Maybe reading this thread will help you [A guide to understanding 'Persistent Context'](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115)

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [25 March 2019 18:21 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/10 "2019-03-25T18:21:24Z")

</div>

HI zenofmud, thanks a lote. I already read this tutorial. But, it served for me to define how to set global variables in the memory or file.  
I tried to get a global variable storage in file using:  
var nwk\_add = global.get('nwk\_addr1',"file") but is not working.

I have success to get the object propertites just using global variable in the memory. As you can see above i have object storage in the memory and file!  
Do you give me help to undertanding it well?

Best Regards,  
Alex

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 March 2019 18:33 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/11 "2019-03-25T18:33:49Z")

</div>

I don't see where in the link posted it says to use that syntax for global.get()

---

<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:** [25 March 2019 19:11 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/12 "2019-03-25T19:11:49Z")

</div>

What did you set in settings.js to define it would be saved in storage?

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [25 March 2019 20:34 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/13 "2019-03-25T20:34:53Z")

</div>

Guys!  
So sorry for my mistake. I was defined to get global variable in the file in the wrong node position. Now is working very well..

```auto
var device = global.get("00137a000000a3bc","file");

```

Best Regards,  
Alex

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [25 March 2019 20:35 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/14 "2019-03-25T20:35:17Z")

</div>

Sorry Colin!

---

<div class="post-metadata">

**Author:** ![SwissAirplane](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@SwissAirplane](https://discourse.nodered.org/u/SwissAirplane)\
**Post date:** [5 June 2019 21:32 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/15 "2019-06-05T21:32:42Z")

</div>

Hello

Unfortunately, this code does not work.  
What's wrong with me? What should I change to work?  
The value of the two global variables is okay for it normally!

 ![ert](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/210381be419fcfe98132fbac5d6aa58f0e8fb4d0.png)

---

<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:** [5 June 2019 21:43 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/16 "2019-06-05T21:43:36Z")

</div>

Hi @SwissAirplane

If you want to share code in the forum, its much easier if you copy and paste the code rather than take a screenshot.

Your syntax is not right. `global.get` is a function, so you should use `()` not `[]`:

```auto
var temp = global.get("temptest");
var hum = global.get("humtest");

```

Looking at the rest of your code, you are not using those variables anywhere.

You do set `msg.payload.svalue` to the string `"temp;hum;0"` - did you mean for `temp` and `hum` in that string to be replaced by the values of those variables?

If so, you could use JavaScript string templates:

```auto
"svalue": `${temp};${hum};0`

```

or simple string concatenation:

```auto
"svalue": temp + ";" + hum + ";0"

```

---

<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:** [27 May 2021 20:45 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/17 "2021-05-27T20:45:32Z")

</div>

Hi there,

I have a challenge that I´m working on now for days, which, for Node-Red Pros is probably the most easy thing to solve. But as I just can´t get my head around it, I just address this to the community and see if this can be easily solved 🙂

Here is my setup: Beside Home Assistant I run another Smart Home System ("Homee") which is providing an API node for Node-Red. This API node is configured to store and constantly update data from all devices added to it in the global context of Node-Red (see picture attached).

Here is my challenge: The whole setup actually works quite well, as all device information gets synched to Node-Red. But now I want to use this information in I all kind of different flows but I just don´t know how to access this data. This can probably be done by any kind of Java Script magic in a function node but as I have literally zero coding skills, I´m quite limited here ☹

Request for help: This may sound pretty simple for you but if anyone could point me in the direction of how to i.e. access a current value from such node that has been stored in global context this would really help me a lot!

 ![Global_context](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4a3575d768f33b8793e4ddff59775bd6bfc9a960.jpeg)

---

<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:** [27 May 2021 21:00 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/18 "2021-05-27T21:00:22Z")

</div>

> [@RonMa](#):
>
> I want to use this information in I all kind of different flows but I just don´t know how to access this data. This can probably be done by any kind of Java Script magic in a function node but as I have literally zero coding skills, I´m quite limited here

As a new user to node-red, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Also, for accessing parts of a message, there’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<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:** [27 May 2021 21:06 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/19 "2021-05-27T21:06:45Z")

</div>

Thanks much @Steve-Mcl for your fast feedback. Maybe I didn´t make myself clear enough: In general I have no issue to access information from any kind of objects. I just struggle with the object data that are stored in the global context as shown in the picture

---

<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:** [27 May 2021 21:40 UTC](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340/20 "2021-05-27T21:40:17Z")

</div>

It's almost the same. Use the copy path button that appears on the item of interest when you hover over it.

Then you can paste that into the change node to copy the value into payload then pass that to the node you want to use.

[Next page](https://discourse.nodered.org/t/how-to-get-global-variable-properties/9340.md?page=2)
