NR 0.17.5 to 1.0.3 upgrade; problem with global context

[{"id":"640d9219.284b4c","type":"DataIn","z":"2499aa94.c14866","collection":"2e31cc75.f3a864","name":"Backup to DB","update":false,"path":"/","x":660,"y":400,"wires":[]},{"id":"d284a4b4.19fa38","type":"inject","z":"2499aa94.c14866","name":"Every 2 hours","topic":"","payload":"","payloadType":"date","repeat":"7200","crontab":"","once":false,"x":160,"y":400,"wires":[["cef9cc4.6793b3"]]},{"id":"cef9cc4.6793b3","type":"function","z":"2499aa94.c14866","name":"Save globals to jsonDB","func":"var d = new Date();\nvar options = { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' };\nvar stamp = d.toLocaleDateString(\"en-GB\", options) + \" \" + d.toLocaleTimeString(\"en-GB\");\nglobal.set(\"lastSaved\", stamp);\nglobal.set(\"lastSavedReason\", msg.topic == \"System Settings Changed\" ? \"System Settings Changed\" : \"Timed Backup\");\nmsg.payload = context.global; //or just global\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":400,"wires":[["640d9219.284b4c"]]},{"id":"2e31cc75.f3a864","type":"json-db-collection","z":"","name":"chSystem","collection":"chSystem","save":true}]

In NR 0.17.5, the above flow, the code msg.payload = context.global; in function "Save globals to jsonDB" dumps all objects in context.global to json-db-node-red and thence to disk for manual/timed backups. It's been working fine for 3 years.

In NR 1.0.3 the same code just produces output containing the global functions get, set and keys.
What is the simplest way of fixing this please? Do I now need to enumerate every object in global perhaps? (I'm keen to keep code/node changes to the bare minimum as this idiom is used in many other places.)

Many thanks for any pointers.

There is a setting in settings.js that provides access to the global root:

    // `global.keys()` returns a list of all properties set in global context.
    // This allows them to be displayed in the Context Sidebar within the editor.
    // In some circumstances it is not desirable to expose them to the editor. The
    // following property can be used to hide any property set in `functionGlobalContext`
    // from being list by `global.keys()`.
    // By default, the property is set to false to avoid accidental exposure of
    // their values. Setting this to true will cause the keys to be listed.
    exportGlobalContextKeys: true,

@TotallyInformation that is not related to the question.

@JayNaire using context.global has not been the recommended way of accessing context for a long time. The proper fix will be to move to the proper way of accessing context and then enabling the persistent context feature that will automatically save context to disk for you.

The alternative will be, as you suggest, enumerate the keys of the context.global object and copy the ones you want into the message before passing it on.

@TotallyInformation Thank you for replying - yes, I had thought exportGlobalContextKeys might have had some bearing on the matter - but now the boss has spoken and now I know!

@knolleary Many thanks for such a speedy reply on a Sunday! I feared that would be the case.

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