Increment a global variable with a change node


is it possible to replace a function node containing the following code, with a change node?

var metric = global.get('metric');
global.set('metric', metric);

Yes that's possible'
Set Global metric
JSONata expression
$globalContext("metric") + 1

1 Like

Thanks! Works great!

Where in the docs would you find that precious little gem?


Of course, I do read the docs and I use that valuable information mentioned there.
However, this JSONata magic

was new to me! I read and re-read that piece of documentation, but I cannot find that JSONata magic! (Or do I miss something? Or can I just not connect the dots?)

Also if you look at the Jsonata expression editor all $functions are listed there, with their parameters.

In case you did not realise, JSONata is just a tool that is included in node-red. If you want a full explanation you need to look in the JSONata documentation.

I agree, that a complete Jsonata re-documentation would be out of scope for Node-RED. IMHO I would like to see the example above, how Jsonata can interact with messages, or context inside the Cookbook ( It would be a good starting point to allude users to this powerful built-in.

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