Is this a bug in the function node withe respect to flow context?

In the attached flow, upon first inject a flow context variable "chargeCurrentLimit" will be initialized.
However, upon a subsequent inject, the test in the function node, "type of flow.chargeCurrentLimit" returns "undefined", while the debug nodes accessing the same variable via $type($flowContext(flow.chargeCurrentLimit)) receive the expected result of "number".

[
    {
        "id": "4b116fb54532a9f7",
        "type": "inject",
        "z": "02e824e32f138746",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{ \"charge_current_limit\" : 100, \"discharge_current_limit\" : -100 }",
        "payloadType": "json",
        "x": 110,
        "y": 100,
        "wires": [
            [
                "d512f75cb2e9157b",
                "9eced449383f1d63"
            ]
        ]
    },
    {
        "id": "e3a65fb2fe7c41b9",
        "type": "inject",
        "z": "02e824e32f138746",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{ \"charge_current_limit\" : 55.2, \"discharge_current_limit\" : -100 }",
        "payloadType": "json",
        "x": 110,
        "y": 160,
        "wires": [
            [
                "d512f75cb2e9157b",
                "9eced449383f1d63"
            ]
        ]
    },
    {
        "id": "1fd130debc1a6350",
        "type": "inject",
        "z": "02e824e32f138746",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{ \"charge_current_limit\" : 25.8, \"discharge_current_limit\" : -100 }",
        "payloadType": "json",
        "x": 110,
        "y": 220,
        "wires": [
            [
                "d512f75cb2e9157b",
                "9eced449383f1d63"
            ]
        ]
    },
    {
        "id": "0887b0fa2eb28079",
        "type": "inject",
        "z": "02e824e32f138746",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{ \"charge_current_limit\" : 0, \"discharge_current_limit\" : -100 }",
        "payloadType": "json",
        "x": 110,
        "y": 280,
        "wires": [
            [
                "d512f75cb2e9157b",
                "9eced449383f1d63"
            ]
        ]
    },
    {
        "id": "9eced449383f1d63",
        "type": "debug",
        "z": "02e824e32f138746",
        "name": "typeof flow.chargeCurrentLimit @inject",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "$type($flowContext(\"chargeCurrentLimit\"))",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 410,
        "y": 160,
        "wires": []
    },
    {
        "id": "d512f75cb2e9157b",
        "type": "function",
        "z": "02e824e32f138746",
        "name": "Check for change in CCL",
        "func": "let msg2 = null;\nnode.warn(\"CCL: \" + Math.abs(msg.payload.charge_current_limit));\nif (typeof flow.chargeCurrentLimit !== \"undefined\") {\n    node.warn(\"FCCL: \" + Math.abs(flow.chargeCurrentLimit));\n    if (Math.abs(flow.chargeCurrentLimit) != \n            Math.abs(msg.payload.charge_current_limit))\n        msg2 = RED.util.cloneMessage(msg); // fire debug showing new limit\n}\nelse {\n    node.warn(\"flow.chargeCurrentLimit type: \" + typeof flow.chargeCurrentLimit);\n    node.warn(\"CCL type: \" + typeof msg.payload.charge_current_limit)\n}\nreturn [msg2, msg]",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 240,
        "wires": [
            [
                "a0e61ca5442b857a"
            ],
            [
                "d87cb57e67c8f319",
                "998a81f4b3d9fd55"
            ]
        ]
    },
    {
        "id": "d87cb57e67c8f319",
        "type": "change",
        "z": "02e824e32f138746",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "chargeCurrentLimit",
                "pt": "flow",
                "to": "$abs(msg.payload.charge_current_limit)",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 420,
        "y": 340,
        "wires": [
            [
                "e3170eefa99548b4",
                "418865778dea68dc"
            ]
        ]
    },
    {
        "id": "b04a8211097eea8c",
        "type": "catch",
        "z": "02e824e32f138746",
        "name": "",
        "scope": null,
        "uncaught": false,
        "x": 360,
        "y": 420,
        "wires": [
            [
                "2d9ea48f5c39b2f7"
            ]
        ]
    },
    {
        "id": "2d9ea48f5c39b2f7",
        "type": "debug",
        "z": "02e824e32f138746",
        "name": "debug 30",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 580,
        "y": 420,
        "wires": []
    },
    {
        "id": "418865778dea68dc",
        "type": "debug",
        "z": "02e824e32f138746",
        "name": "typeof flow.chargeCurrentLimit",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "$type($flowContext(\"chargeCurrentLimit\"))",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 750,
        "y": 380,
        "wires": []
    },
    {
        "id": "e3170eefa99548b4",
        "type": "debug",
        "z": "02e824e32f138746",
        "name": "done changing",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 700,
        "y": 340,
        "wires": []
    },
    {
        "id": "998a81f4b3d9fd55",
        "type": "debug",
        "z": "02e824e32f138746",
        "name": "setting new FCCL",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.charge_current_limit",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 280,
        "wires": []
    },
    {
        "id": "a0e61ca5442b857a",
        "type": "debug",
        "z": "02e824e32f138746",
        "name": "New charge current limit",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.charge_current_limit",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 240,
        "wires": []
    }
]

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

You should use flow.get("chargeCurrentLimit") to get the value.

thanks! I realized that on my own this evening.

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