How to set a global variable in a function node base on an svg event

Hello,
I am trying to set a global variable in a function node base on an svg js event.
I want that the variable should only be set when an event occur in the svg node (when the user click on a button in the svg node). Here below is my code which isn't responding as needed.

{
   "command":"add_js_event",
    "event":"click",
    "elementId":"alarm",
    "script":"global.set('fault',1)"
    }

Any help on this, pls....

scripts running in SVG (or HTML) events are executed on the client side (AKA in the browser) not in the server (AKA Node-RED)

If you want to affect global context, feed the value back to Node-RED then use a change node or function node to set the global context.

I assume you are using node-red-contrib-ui-svg?

Read its docs - you can have events send values back to node-red (they come out of the SVG node) - wire that to a debug to see what you get.

You're right, it works.
Thanks Steve

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