Initial global variable not working debug undefined

Hi

I am having a change node to set a global variable
triggery by time inject node

wondering why after deployment variable is not defined.

checking with debug node

what am I missing?

[{"id":"510cbd9c.4b2f24","type":"inject","z":"322adaad.4e52d6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":70,"y":140,"wires":[["19d20c76.08dc54","9985e5a6.4fa788"]]},{"id":"9985e5a6.4fa788","type":"change","z":"322adaad.4e52d6","name":"Parameter","rules":[{"t":"set","p":"test_global","pt":"global","to":"init","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":540,"wires":[["2ebf8083.e9338"]]},{"id":"2ebf8083.e9338","type":"debug","z":"322adaad.4e52d6","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"global.test_global","targetType":"msg","statusVal":"payload.soc_toggle_low","statusType":"auto","x":570,"y":540,"wires":[]}]

Thanks t

https://nodered.org/docs/user-guide/context
What kind of context storage option you are using? Persistent context memory is not default option, it must be configured to take effect.

Hi Thanks,

did not change the default setting yet.

but I assumed that having the inject after deployment the global variable should be set via change node ?

I also used some functions with global.get() , which was not working

have to check the context options

There is nothing wrong with the way which you have set the Global context, the error is arising from the debug node containing global.test_global as its output.
You cannot obtain the Global context like that, you need to retrieve it first using a change or function node, and then feed that into the debug.

However, you could add a little jsonata to the debug node to output your Global context. try;

[{"id":"9985e5a6.4fa788","type":"change","z":"b3b413d1.05b1b","name":"Parameter","rules":[{"t":"set","p":"test_global","pt":"global","to":"init","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1530,"wires":[["2ebf8083.e9338"]]},{"id":"2ebf8083.e9338","type":"debug","z":"b3b413d1.05b1b","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"$globalContext('test_global')","targetType":"jsonata","statusVal":"payload.soc_toggle_low","statusType":"auto","x":510,"y":1530,"wires":[]},{"id":"b5f8b3a7.fdd3c","type":"inject","z":"b3b413d1.05b1b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":145,"y":1530,"wires":[["9985e5a6.4fa788"]]}]

context

ok understood, will try with a function node

Perfect, thanks, this is working

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