r/nodered•
debegr92

Custom node property calculation not updated

Hi,

I have a custom node and try to calculate some kind of array from the text input. It is like a number filter, where you can put "1,2,3,42-45,999" in. Later I try to filter a code out.

It is working once, but after changing and redeploy, the values of my filter array do not change. After fully restart Node-RED, the values are there. What do I miss? Can't figure out by the tutorial and other nodes.

module.exports = function(RED) {

    function ReceiveEventNode(config) {
        RED.nodes.createNode(this, config);
        var node = this;

        // Retrieve the config node
        node.configNode = RED.nodes.getNode(config.server);

        // Get parameters
        node.userEventsFilter = config.userEventsFilter;    // 42-45
        node.userEventsFilterArray = parseFilterString(node.userEventsFilter);  // now: [42,43,44,45]

        if (node.configNode) {
            node.configNode.addListener("event", function(msg) {
                // Check if msg.code is in array
                if(node.userEventsFilterArray.indexOf(msg.code) > -1){
                    // Do something

                    // !!! userEventsFilterArray has old values !!!
                }
            });
        }
    }
    RED.nodes.registerType("receive-event", ReceiveEventNode);
}

My property from the node is userEventsFilter. I calculate an array of numbers out of it (userEventsFilterArray) to easy check, if the code is included or excluded.

Posted Jun 29, 2021, 9:34 PM UTC

10

No comments yet

Nobody commented on this post, or the comments weren't captured.