# No data on second function output

**URL:** <https://discourse.nodered.org/t/no-data-on-second-function-output/90111>\
**Category:** General\
**Tags:** function-node\
**Created:** [11 August 2024 16:37 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111 "2024-08-11T16:37:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [11 August 2024 16:37 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/1 "2024-08-11T16:37:24Z")

</div>

```auto
var msg2 = [{payload:"",filename:""}];

msg2.filename = "test";
msg2.payload = "test2";

msg.payload = "test3";

return [msg,msg2];

```

Though I fill msg2.filename and msg2.payload with data, the second debug output shows only the empty strings from line 1!??

complete flow to test:

```auto
[
    {
        "id": "e82841526f31da38",
        "type": "function",
        "z": "ada67f26f66765ce",
        "name": "",
        "func": "var msg2 = [{payload:\"\",filename:\"\"}];\n\nmsg2.filename = \"test\";\nmsg2.payload = \"test2\";\n\nmsg.payload = \"test3\";\n\nreturn [msg,msg2];\n",
        "outputs": 2,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 200,
        "wires": [
            [
                "5240e61ec7f320bf"
            ],
            [
                "ae5614bcead71a36"
            ]
        ]
    },
    {
        "id": "875462fc390b6934",
        "type": "inject",
        "z": "ada67f26f66765ce",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 220,
        "y": 200,
        "wires": [
            [
                "e82841526f31da38"
            ]
        ]
    },
    {
        "id": "5240e61ec7f320bf",
        "type": "debug",
        "z": "ada67f26f66765ce",
        "name": "debug 35",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 160,
        "wires": []
    },
    {
        "id": "ae5614bcead71a36",
        "type": "debug",
        "z": "ada67f26f66765ce",
        "name": "debug 36",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 240,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [11 August 2024 16:43 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/2 "2024-08-11T16:43:01Z")

</div>

No need an array for the second output.

```js
var msg2 = {payload:"test2",filename:"test"};
msg.payload = "test3";

return [msg,msg2];

```

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [11 August 2024 18:49 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/3 "2024-08-11T18:49:11Z")

</div>

The above demo is simple, but I want to change both of the values during the code, so I cannot set them at the beginning!?  
But it is valid to change the values during the function code, isn't it?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 August 2024 19:12 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/4 "2024-08-11T19:12:18Z")

</div>

> [@stefan24](#):
>
> it is valid to change the values during the function code, isn't it?

You can change the values as many times as you desire. The only time it matters is when you `return` them.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [11 August 2024 19:18 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/5 "2024-08-11T19:18:29Z")

</div>

I did this many times before. But then why does my `debug 36` not return the values above??  
BTW: I test it on Node-RED 4.0.2. My Smart-home Node-RED is still at 3.1.9, but I can reproduce the same effect there.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 August 2024 19:22 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/6 "2024-08-11T19:22:39Z")

</div>

> [@stefan24](#):
>
> `var msg2 = [{payload:"",filename:""}];`

Have you taken the square brackets off? It should be  
`var msg2 = {payload:"",filename:""};`

You should use `let` rather than `var`, but that is not what is causing the problem.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [11 August 2024 19:24 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/7 "2024-08-11T19:24:48Z")

</div>

Thanks, @Colin ! That was the error!!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 August 2024 20:57 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/8 "2024-08-11T20:57:12Z")

</div>

> [@stefan24](#):
>
> That was the error

@GogoVega did point that out in his first post. It is that one you should mark as the solution.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 August 2024 20:57 UTC](https://discourse.nodered.org/t/no-data-on-second-function-output/90111/9 "2024-08-25T20:57:39Z")

</div>

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