Change Node does not change payload when using variables

Hope I'm not repeating a question, couldn't find an appropriate existing thread.

I'm trying to make a flow that uses flow context variables, rather than static values set throughout different nodes within the flow.

So I started a tab containing two wired node sets.
One flow sets the flow context variables to the unique values.
The other flow is the work, and supposed to use the context variables to set data values.

The first payload is an array returned from an SNMP query, so I have a change node move the data I want from the array to just msg.payload. This works fine.

Then the variables come into play.
I added rules to change msg.payload: search for flow.variable1, replace with flow.variable2.

It ignores the search/replace rules.

I added a switch node to see if it's actually reading the data within variable, and it does appear to be.

What am I doing wrong?

*Edited to hopefully make more comprehensible.

[
    {
        "id": "09d82a28e3e9a8f1",
        "type": "tab",
        "label": "Troubleshooting Iso",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "c44cf6f571661e68",
        "type": "ui_text",
        "z": "09d82a28e3e9a8f1",
        "group": "3990be236485e116",
        "order": 1,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Current Monitor: ",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "className": "",
        "x": 1480,
        "y": 340,
        "wires": []
    },
    {
        "id": "ee949e0b114a624e",
        "type": "change",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "rules": [
            {
                "t": "move",
                "p": "payload.0.value",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "signal1",
                "fromt": "flow",
                "to": "calls1",
                "tot": "flow"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "signal2",
                "fromt": "flow",
                "to": "calls2",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "FM-INO",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 700,
        "y": 340,
        "wires": [
            [
                "03297ae82a54b210",
                "b7188842c064e69d",
                "cc0e8dfe53848d02"
            ]
        ]
    },
    {
        "id": "640907369cca4843",
        "type": "inject",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "props": [
            {
                "p": "payload.0.value",
                "v": "9510",
                "vt": "num"
            }
        ],
        "repeat": "12",
        "crontab": "",
        "once": true,
        "onceDelay": ".1",
        "topic": "",
        "x": 270,
        "y": 340,
        "wires": [
            [
                "ee949e0b114a624e"
            ]
        ]
    },
    {
        "id": "f49ada1a78f429d9",
        "type": "change",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "calls1",
                "pt": "flow",
                "to": "Station1",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "signal1",
                "pt": "flow",
                "to": "9510",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "calls2",
                "pt": "flow",
                "to": "Station2",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "signal2",
                "pt": "flow",
                "to": "10410",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 480,
        "y": 200,
        "wires": [
            [
                "971f32048ed00c38"
            ]
        ]
    },
    {
        "id": "cc0e8dfe53848d02",
        "type": "change",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "FM-INO",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 980,
        "y": 340,
        "wires": [
            [
                "0f47b7e8e9273f2f",
                "c44cf6f571661e68"
            ]
        ]
    },
    {
        "id": "90b9a97fa38933f1",
        "type": "inject",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 270,
        "y": 200,
        "wires": [
            [
                "f49ada1a78f429d9"
            ]
        ]
    },
    {
        "id": "e8b88d95da60f69b",
        "type": "debug",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 850,
        "y": 200,
        "wires": []
    },
    {
        "id": "971f32048ed00c38",
        "type": "change",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "calls1",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "payload2",
                "pt": "msg",
                "to": "signal1",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "payload3",
                "pt": "msg",
                "to": "calls2",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "payload4",
                "pt": "msg",
                "to": "signal2",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 680,
        "y": 200,
        "wires": [
            [
                "e8b88d95da60f69b"
            ]
        ]
    },
    {
        "id": "0f47b7e8e9273f2f",
        "type": "debug",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1150,
        "y": 280,
        "wires": []
    },
    {
        "id": "03297ae82a54b210",
        "type": "debug",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 850,
        "y": 280,
        "wires": []
    },
    {
        "id": "b7188842c064e69d",
        "type": "switch",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "signal1",
                "vt": "flow"
            },
            {
                "t": "eq",
                "v": "signal2",
                "vt": "flow"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 950,
        "y": 440,
        "wires": [
            [
                "91f6f57ff1ab93ea"
            ],
            [
                "5ab7ce158e853e99"
            ]
        ]
    },
    {
        "id": "401e44489a9d2d41",
        "type": "debug",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1450,
        "y": 420,
        "wires": []
    },
    {
        "id": "728433af94ef31d0",
        "type": "debug",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1450,
        "y": 460,
        "wires": []
    },
    {
        "id": "91f6f57ff1ab93ea",
        "type": "change",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "signal1",
                "fromt": "flow",
                "to": "turtle",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "signal2",
                "fromt": "flow",
                "to": "calls2",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1240,
        "y": 420,
        "wires": [
            [
                "401e44489a9d2d41"
            ]
        ]
    },
    {
        "id": "5ab7ce158e853e99",
        "type": "change",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "signal1",
                "fromt": "flow",
                "to": "turtle",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "signal2",
                "fromt": "flow",
                "to": "frog",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1240,
        "y": 460,
        "wires": [
            [
                "728433af94ef31d0"
            ]
        ]
    },
    {
        "id": "f75ace522f327043",
        "type": "inject",
        "z": "09d82a28e3e9a8f1",
        "name": "",
        "props": [
            {
                "p": "payload.0.value",
                "v": "10410",
                "vt": "num"
            }
        ],
        "repeat": "6",
        "crontab": "",
        "once": true,
        "onceDelay": "6",
        "topic": "",
        "x": 270,
        "y": 400,
        "wires": [
            [
                "ee949e0b114a624e"
            ]
        ]
    },
    {
        "id": "3990be236485e116",
        "type": "ui_group",
        "name": "Test",
        "tab": "9aa0f74a5fd39f0f",
        "order": 3,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "9aa0f74a5fd39f0f",
        "type": "ui_tab",
        "name": "Monitor System",
        "icon": "device_hub",
        "disabled": false,
        "hidden": false
    }
]

I have not tried your flow, and don't fully understand your description, but if you are setting flow context in one flow, and trying to access it in a different flow, it will fail.
Should you be using global context?

No, I'm accessing it in the same editor tab, and as I understand the description, making it within the same flow.

I have two separate sets of wired nodes acting in the tab. The first sets the values of the flow context variables.
The second uses those variables to do stuff.
The problem I'm hitting is that the second set of nodes does indeed read the correct values from the variables, but the Change node isn't acting on them. The switch node will act on variables, but change node ignores.
I also dropped the change node in the set of nodes where I initially set the context variables in case it was a cross-flow issue, but it behaves the same way, ignores the variables.

The problem appears to be solely in the change node.

I think I've narrowed this down to the change node, in find/replace mode, does not read flow.context variables. I have one Change node set the payload to the variable, then the next Change node search for that variable. The resulting output is the payload set by the first Change node. The second Change node seems unable to use the variable in a search-replace action.

I tested your flow - and got the same result. In my opinion it is a bug in the change node - or if it is not intended to change a payload with the content of a flow variable, then the flow option should not be offered in the change setting .

I've not loaded the flow (on phone) but the replace only works on/in strings. Is the payload a string ?

No there is no difference - neither strings or numbers (which was the original flow) works.

image

That could be the issue. The original payload is a number/int, and the value to compare is a number. I didn't try it with a string and ended up making a large switch matrix into individual Change nodes that set the other variables.

image

But I have a workround for you - using JSONATA in the change node:

Zusammenfassung

[ { "id": "b1d84cdc1f90566c", "type": "change", "z": "99be628872a99c35", "name": "", "rules": [ { "t": "move", "p": "payload.0.value", "pt": "msg", "to": "payload", "tot": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload = $flowContext(\"signal1\") ? $flowContext(\"calls1\") : payload", "tot": "jsonata" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload = $flowContext(\"signal2\") ? $flowContext(\"calls2\") : payload", "tot": "jsonata" }, { "t": "set", "p": "FM-INO", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 700, "y": 340, "wires": [ [ "3e8c5d96830c5e31", "3a19fb6eba096712", "44657395a1dd86f7" ] ] } ]

1 Like

No I checked already - strings will not work either . But I posted a workaround with the change node. It is not a string replace as original - but changes payload as intended.

I ran some tests and discovered that if the find is a flow variable it will not work. But you can add a rule before doing the fine to set a msg variable to the flow.find variable and that will work.

Here a sample set of cases to show the issue and 'get around' solution

[{"id":"ff442022d2d639f1","type":"tab","label":"test change with flow variables","disabled":false,"info":"","env":[]},{"id":"730d27690bb13673","type":"inject","z":"ff442022d2d639f1","name":"THIS WORKS - msg.find msg.replace","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":80,"wires":[["73b9c7541fc52969"]]},{"id":"d61fff70a6d25e03","type":"debug","z":"ff442022d2d639f1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":80,"wires":[]},{"id":"73b9c7541fc52969","type":"change","z":"ff442022d2d639f1","name":"set variables","rules":[{"t":"set","p":"payload","pt":"msg","to":"1234","tot":"num"},{"t":"set","p":"find","pt":"msg","to":"1234","tot":"num"},{"t":"set","p":"replace","pt":"msg","to":"msg.find msg.replace","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":80,"wires":[["718fe75c23820acf"]]},{"id":"718fe75c23820acf","type":"change","z":"ff442022d2d639f1","name":"do find/replace","rules":[{"t":"change","p":"payload","pt":"msg","from":"find","fromt":"msg","to":"replace","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":80,"wires":[["d61fff70a6d25e03"]]},{"id":"47bde1d6716d0e9d","type":"inject","z":"ff442022d2d639f1","name":"THIS FAILS - flow.find msg.replace","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":140,"wires":[["c86cb480b9485838"]]},{"id":"9e3a0f24298b808b","type":"debug","z":"ff442022d2d639f1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":140,"wires":[]},{"id":"c86cb480b9485838","type":"change","z":"ff442022d2d639f1","name":"set variables","rules":[{"t":"set","p":"payload","pt":"msg","to":"1234","tot":"num"},{"t":"set","p":"find","pt":"flow","to":"1234","tot":"num"},{"t":"set","p":"replace","pt":"msg","to":"flow.find msg.replace","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":140,"wires":[["5c1371ea05ab1050"]]},{"id":"5c1371ea05ab1050","type":"change","z":"ff442022d2d639f1","name":"do find/replace","rules":[{"t":"change","p":"payload","pt":"msg","from":"find","fromt":"flow","to":"replace","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":140,"wires":[["9e3a0f24298b808b"]]},{"id":"61e316a09c9a73e2","type":"inject","z":"ff442022d2d639f1","name":"THIS WORKS - msg.find flow.replace","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":200,"wires":[["0d8a1559c9989b84"]]},{"id":"f6f8b860a0f4f748","type":"debug","z":"ff442022d2d639f1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":200,"wires":[]},{"id":"0d8a1559c9989b84","type":"change","z":"ff442022d2d639f1","name":"set variables","rules":[{"t":"set","p":"payload","pt":"msg","to":"1234","tot":"num"},{"t":"set","p":"find","pt":"msg","to":"1234","tot":"num"},{"t":"set","p":"replace","pt":"flow","to":"msg.find flow.replace","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":200,"wires":[["a4a9f70153ee0936"]]},{"id":"a4a9f70153ee0936","type":"change","z":"ff442022d2d639f1","name":"do find/replace","rules":[{"t":"change","p":"payload","pt":"msg","from":"find","fromt":"msg","to":"replace","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":200,"wires":[["f6f8b860a0f4f748"]]},{"id":"5675c777df9f575f","type":"inject","z":"ff442022d2d639f1","name":"THIS FAILS - flow.find flow.replace","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":260,"wires":[["e9d947e07e045dfc"]]},{"id":"c9a74e0223b1c150","type":"debug","z":"ff442022d2d639f1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":260,"wires":[]},{"id":"e9d947e07e045dfc","type":"change","z":"ff442022d2d639f1","name":"set variables","rules":[{"t":"set","p":"payload","pt":"msg","to":"1234","tot":"num"},{"t":"set","p":"find","pt":"flow","to":"1234","tot":"num"},{"t":"set","p":"replace","pt":"flow","to":"flow.find flow.replace","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":260,"wires":[["1de5b96e8447704e"]]},{"id":"1de5b96e8447704e","type":"change","z":"ff442022d2d639f1","name":"do find/replace","rules":[{"t":"change","p":"payload","pt":"msg","from":"find","fromt":"flow","to":"replace","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":260,"wires":[["c9a74e0223b1c150"]]},{"id":"cda70b53f175a9cd","type":"inject","z":"ff442022d2d639f1","name":"THIS WORKS - flow.find flow.replace hack","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":380,"wires":[["d76b53e0b32548ad"]]},{"id":"c8f44da8ea618fa2","type":"debug","z":"ff442022d2d639f1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":380,"wires":[]},{"id":"d76b53e0b32548ad","type":"change","z":"ff442022d2d639f1","name":"set variables","rules":[{"t":"set","p":"payload","pt":"msg","to":"1234","tot":"num"},{"t":"set","p":"find","pt":"flow","to":"1234","tot":"num"},{"t":"set","p":"replace","pt":"flow","to":"msg.find flow.replace hack","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":380,"wires":[["0ae51a133d78b2f9"]]},{"id":"0ae51a133d78b2f9","type":"change","z":"ff442022d2d639f1","name":"do a move then find/replace","rules":[{"t":"set","p":"find","pt":"msg","to":"find","tot":"flow"},{"t":"change","p":"payload","pt":"msg","from":"find","fromt":"msg","to":"replace","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":380,"wires":[["c8f44da8ea618fa2"]]}]
1 Like

Thanks for the replies and workarounds. :+1: :+1:
I ended up already swapping in the little switch matrix to the 4 tabs I was working on, but in the next overhaul, I will try the workarounds. Thanks again.

I had experienced the same issue and resolved it by putting the info in msg. instead of a flow variable. I do believe it is maybe a bug in the change node.

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