Global context variables do not display in the Context Sidebar

Yes. Exacty what I explained in my last reply.

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

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 }

:roll_eyes:

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'); ?

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.

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

Puzzling indeed....

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

[{"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":[]}]

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.

@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)

The Context sidebar now works for me in v0.19.4

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.

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.

been there, done that. :grinning:

Done that! :grin:

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?

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

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,

Update:
new flows.json file totally blank.

[{"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":[]}]

  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.

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

1 Like

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

[{"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

I get exactly the same thing....