Whats wrong here with getting enviroment variables?

Just updated to V3.1 and now, for the first time, wanna try to use global enviroment variables. But I am already stucked with this first example. Output is nil or undefined
An enviroment variable NAME has been defined via the new editor.

[
    {
        "id": "3412699fcff8c757",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "5fbc9d8c656aa129",
        "type": "inject",
        "z": "3412699fcff8c757",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "${NAME}",
        "payloadType": "env",
        "x": 350,
        "y": 360,
        "wires": [
            [
                "429749928b1530b7",
                "c1be07a0c1ea5915"
            ]
        ]
    },
    {
        "id": "429749928b1530b7",
        "type": "debug",
        "z": "3412699fcff8c757",
        "name": "setting_out",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 360,
        "wires": []
    },
    {
        "id": "c1be07a0c1ea5915",
        "type": "function",
        "z": "3412699fcff8c757",
        "name": "function 1",
        "func": "var nmsg = { \"payload\" : env.get('NAME')};\nreturn nmsg",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 280,
        "wires": [
            [
                "b7ad803777339e0a"
            ]
        ]
    },
    {
        "id": "b7ad803777339e0a",
        "type": "debug",
        "z": "3412699fcff8c757",
        "name": "func_out",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 280,
        "wires": []
    }
]

Hi @haegar33

In your Inject node, the property should be NAME not ${NAME}

As you have set the field type as 'env var', if you use ${NAME} then the runtime will first substitute the value of ${NAME} with the value of the NAME env var... which is then used as the name of the env var to lookup for the field...

1 Like

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