# Global context variables do not display in the Context Sidebar

**URL:** <https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153>\
**Category:** General\
**Created:** [14 September 2018 20:22 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153 "2018-09-14T20:22:47Z")\
**Posts on this page:** 20\
**Page:** 4

<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:** [21 September 2018 14:02 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/61 "2018-09-21T14:02:31Z")

</div>

Yes. Exacty what I explained in my last reply.

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 14:05 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/62 "2018-09-21T14:05:44Z")

</div>

Nick,  
I tried this function. I set the variable with global.set('mynewvar') with a prior function. and it stored the value correctly.

```auto
var keys = global.keys();
var v,k;
var pl = {}
for(var i in keys){
  v = global.get(keys[i])
  k = keys[i]
  pl[k] = v
   
}
msg.payload = pl
return msg;

```

Then ran this function and it returns

msg.payload : Object  
{ empty }

🙄

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 14:09 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/63 "2018-09-21T14:09:20Z")

</div>

Nick,  
I was under the impression that you had 2 ways of getting the values on the SAME variable... Not that you had two ways of storing different globals with the same name...

Ok, now that is clear...

Now, how do I get the global.keys() to read the global variable stored by global.set('mynewvar','123'); ?

---

<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:** [21 September 2018 14:23 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/64 "2018-09-21T14:23:49Z")

</div>

> [@tree-frog](#):
>
> Now, how do I get the global.keys() to read the global variable stored by global.set('mynewvar','123'); ?

That is the central question here. The code you've shared works for me. Internally we use `global.keys()` when getting the contents to display in the context sidebar.

The fact `global.keys()` isn't returning anything will be reason your sidebar doesn't show anything.

So the question is why does global.keys() not work for you, but it works for everyone else.

I still don't have any idea what could be different about your environment to explain that.

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 14:33 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/65 "2018-09-21T14:33:46Z")

</div>

Nick,  
The program is under my profile in \Users\'my name and domain'\.node-red\flows\_'computername'.json

When upgrading nodes that are already installed, i needed to uninstall them and install them again with the palette. That shouldn't have any affect on the runtime namespace. It appears that everything works the way it should except for the keys() function here. Is there a reference in this that assumes a default namespace somehow?, but in my case it is different? How could everything work the way it does, fine, and then this become an issue?

Kyle

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [21 September 2018 17:43 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/66 "2018-09-21T17:43:15Z")

</div>

> [@tree-frog](#):
>
> Then ran this function and it returns
> 
> msg.payload : Object  
> { empty }

Puzzling indeed....

May you try this flow , press the inject node twice or three times and upload here a screenshot of the debug panel ?

```auto
[{"id":"3ecaedc3.1b2c42","type":"tab","label":"Flow 11","disabled":false,"info":""},{"id":"54517068.54daf","type":"function","z":"3ecaedc3.1b2c42","name":"Asynchronous context access","func":"global.get('count', function(err, count) {\n if (err) {\n node.error(err, msg);\n } else {\n // initialise the counter to 0 if it doesn't exist already\n count = count || 0;\n count += 1;\n // store the value back\n global.set('count',count, function(err) {\n if (err) {\n node.error(err, msg);\n } else {\n // make it part of the outgoing msg object\n msg.count = count;\n // send the message\n node.send(msg);\n }\n });\n }\n});\n\n","outputs":1,"noerr":0,"x":390,"y":240,"wires":[["38407bc6.4ce9c4"]]},{"id":"38407bc6.4ce9c4","type":"debug","z":"3ecaedc3.1b2c42","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":610,"y":240,"wires":[]},{"id":"86b63bf6.24bd68","type":"inject","z":"3ecaedc3.1b2c42","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":240,"wires":[["54517068.54daf"]]},{"id":"6e1f2dcb.43f5a4","type":"catch","z":"3ecaedc3.1b2c42","name":"","scope":null,"x":200,"y":360,"wires":[["cce7299d.fb14f8"]]},{"id":"cce7299d.fb14f8","type":"debug","z":"3ecaedc3.1b2c42","name":"Debug Catch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":420,"y":360,"wires":[]}]

```

---

<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:** [21 September 2018 17:52 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/67 "2018-09-21T17:52:23Z")

</div>

Can you try (or maybe you have already..?) Move your existing flow file sideways and start with a completely blank one. Then add in a simple test of using global context. I would like to rule out anything in your flow causing some sort of internal corruption of the global context object.

---

<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:** [21 September 2018 18:18 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/68 "2018-09-21T18:18:15Z")

</div>

@tree-frog - You are on nr v0.19.3 correct? Can you try upgrading to v0.19.4 and see if the issue still exists.  
@knolleary - I discussed a problem with the contect variables (in v0.19.) two weeks ago - I even opened an issue in github with the node-red-contrib-contextbrowser because it was hitting the error (see: [https://github.com/sbarwe/node-red-contrib-contextbrowser/issues/5](https://github.com/sbarwe/node-red-contrib-contextbrowser/issues/5))

The Context sidebar now works for me in v0.19.4

---

<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:** [21 September 2018 19:01 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/69 "2018-09-21T19:01:12Z")

</div>

The context.keys not a function error was a result of the users flow actively deleting context keys. 0.19.4 makes it impossible to accidentally delete context.keys.

But none of that is related to the contextbrowser sidebar - it just hit the error beacause the users flow had deleted the function the sidebar was trying to use. So I'm not sure what the issue is meant to address in the contextbrowser sidebar.

Now obviously the built-in sidebar does render that contrib sidebar a bit redundant... So pursuing fixes in it is perhaps not entirely worthwhile.

---

<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:** [21 September 2018 19:17 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/70 "2018-09-21T19:17:06Z")

</div>

One other note/thought - if you have the sidebar context viewer open and then create a flow context variable, you need to press the refresh icon to see the new variables show up. I stumbled over that in the beginning. Same thing if you delete a context variable, it doesn't automatically update the sidebar.

 ![53%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2ea4dcc8190737fca5dfae0d9a78fd0a59ad0498.png)

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 19:37 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/71 "2018-09-21T19:37:32Z")

</div>

been there, done that. 😀

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 19:38 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/72 "2018-09-21T19:38:03Z")

</div>

Done that! 😁

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 19:39 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/73 "2018-09-21T19:39:50Z")

</div>

On that note, Is there a means to start off with a blank slate and keep your existing file, by just renaming it?  
If you do rename it, Does the system know enough to start a new blank one?

---

<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:** [21 September 2018 19:45 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/74 "2018-09-21T19:45:34Z")

</div>

If you mean your flow file - yes I do it all the time. You can just start NR with node-red mytest.json or node-red project1.json

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 19:47 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/75 "2018-09-21T19:47:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 20:03 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/76 "2018-09-21T20:03:26Z")

</div>

Do you specify the new blank file in the config file ? Or where?...  
I figured it out.

Modified the "settings.js" file. added the item "flowFile: 'flows\_MyName.json',  
with a new name other than default.

I'll delete the entry and it should revert back to my program later.  
Thanks,

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 20:31 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/77 "2018-09-21T20:31:16Z")

</div>

Update:  
new flows.json file totally blank.

```auto
[{"id":"5a65d8f4.d8902","type":"inject","z":"c19b1b8.e6a7e68","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":790,"y":60,"wires":[["bfd40901.dba36"]]},{"id":"bfd40901.dba36","type":"function","z":"c19b1b8.e6a7e68","name":"global set mynewvar = 123","func":"global.set('mynewvar','123')\nreturn msg;","outputs":1,"noerr":0,"x":1040,"y":60,"wires":[["2aeb26c9.cdac32"]]},{"id":"2aeb26c9.cdac32","type":"debug","z":"c19b1b8.e6a7e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1290,"y":60,"wires":[]},{"id":"c50b07ea.dfb018","type":"inject","z":"c19b1b8.e6a7e68","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":790,"y":140,"wires":[["fc85c412.1b301"]]},{"id":"fc85c412.1b301","type":"function","z":"c19b1b8.e6a7e68","name":"global keys()","func":"var keys = global.keys();\nvar v,k;\nvar pl = {}\nfor(var i in keys){\n v = global.get(keys[i])\n k = keys[i]\n pl[k] = v\n \n}\nmsg.payload = pl\nreturn msg;","outputs":1,"noerr":0,"x":990,"y":140,"wires":[["255c65c1.3d02a2"]]},{"id":"255c65c1.3d02a2","type":"debug","z":"c19b1b8.e6a7e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1250,"y":140,"wires":[]},{"id":"62c7f95a.0d8f38","type":"inject","z":"c19b1b8.e6a7e68","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":790,"y":100,"wires":[["91ee10db.284e8"]]},{"id":"91ee10db.284e8","type":"function","z":"c19b1b8.e6a7e68","name":"global get mynewvar","func":"var v = global.get('mynewvar');\nmsg.payload = v;\nreturn msg;","outputs":1,"noerr":0,"x":1020,"y":100,"wires":[["1500b2f5.58ac3d"]]},{"id":"1500b2f5.58ac3d","type":"debug","z":"c19b1b8.e6a7e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1270,"y":100,"wires":[]}]

```

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

1. global.set() write mynewvar = 123
2. global.get() read mynewvar value = 123
3. global.keys(). {empty}

global.keys() apparently does not work for me for some strange reason.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [21 September 2018 20:33 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/78 "2018-09-21T20:33:20Z")

</div>

You just need to add it to the command line. Try node-red -?

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [21 September 2018 20:50 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/79 "2018-09-21T20:50:53Z")

</div>

> [@tree-frog](#):
>
> global.keys() apparently does not work for me for some strange reason.

amazing... what do you get if you run this simple flow ?

```auto
[{"id":"8062e897.529a88","type":"tab","label":"Flow 13","disabled":false,"info":""},{"id":"6048d320.a191ec","type":"function","z":"8062e897.529a88","name":"","func":"node.warn(global);\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":140,"wires":[["f70d875d.51b9c8"]]},{"id":"40a7de91.f8bac","type":"inject","z":"8062e897.529a88","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":140,"wires":[["6048d320.a191ec"]]},{"id":"f70d875d.51b9c8","type":"debug","z":"8062e897.529a88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":620,"y":140,"wires":[]}]

```

This is my result:

![r-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d3b3f24f2853852d2b3f324c282ddb28ca1be57c.png)

---

<div class="post-metadata">

**Author:** ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)\
**Post date:** [21 September 2018 20:55 UTC](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153/80 "2018-09-21T20:55:10Z")

</div>

I get exactly the same thing....

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

[Previous page](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153.md?page=3)

[Next page](https://discourse.nodered.org/t/global-context-variables-do-not-display-in-the-context-sidebar/3153.md?page=5)
