# Help - CSV node issue

**URL:** <https://discourse.nodered.org/t/help-csv-node-issue/21983>\
**Category:** General\
**Created:** [19 February 2020 13:07 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983 "2020-02-19T13:07:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [19 February 2020 13:07 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/1 "2020-02-19T13:07:55Z")

</div>

Hi people.  
I'm having a little trouble with the CSV node.  
After many hours of tests, now I'm able to export my data into a .csv file.  
The issue is that my exported values are plotted individually in different rows: I would plot them in different columns.

 ![Cattura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10b1d7af6b838f1008a34892d05e996f817c887c.png)

Mercy me, I don't know how better attach my debug...  
Bye.

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [19 February 2020 13:24 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/2 "2020-02-19T13:24:33Z")

</div>

Forgot my EXCEL function...  
 ![Cattura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/b/2b01902c2065d393b9a3f5c119f82c417212b487.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 February 2020 13:31 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/3 "2020-02-19T13:31:24Z")

</div>

try msg.payload = z0 + "," + z1 +"," + etc, etc

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [19 February 2020 13:48 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/4 "2020-02-19T13:48:31Z")

</div>

msg.payload : array[0]  
[empty]

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 February 2020 14:08 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/5 "2020-02-19T14:08:53Z")

</div>

Let me see your function node now. I should have said you should only use  
`return msg`  
After setting msg.payload

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [19 February 2020 16:27 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/6 "2020-02-19T16:27:11Z")

</div>

If I would do like you are saying, then the msg.payload would be a unique string, and in my csv file would only one row/one column

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 February 2020 17:47 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/7 "2020-02-19T17:47:34Z")

</div>

Sorry I didn't realize your input was an array. What you need to do is build an array where each entry in the array is a string of values seperated by commas. In your case it loks like you want to send what ever is in msg.payload[2] plus the time and the date. Three columns so you would use

```auto
var a = [];
a[0] = msg.payload[2] +"," + t +',' + tt;
a[1] = msg.payload[3] +"," + t +',' + tt;
msg.payload = a;
return msg;

```

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [19 February 2020 18:32 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/8 "2020-02-19T18:32:02Z")

</div>

It doesn't work.... It reurns, in an unique row/column:

400,19:29,19/02/2020,"550,19:29,19/02/2020"

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 February 2020 18:52 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/9 "2020-02-19T18:52:00Z")

</div>

Sorry, don't know where my brain is today. it shouldn't be a array, but a string where each line ends with a new line `\n` character

```auto
var a = '';
a = msg.payload[2] +"," + t +',' + tt + '\n';
a += msg.payload[3] +"," + t +',' + tt + '\n';
msg.payload = a;
return msg;

```

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [19 February 2020 19:20 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/10 "2020-02-19T19:20:10Z")

</div>

Sorry, but your last one seems to be completely wrong..

[{"400":"550","20:16":"20:16","19/02/2020":"19/02/2020"}]

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 February 2020 21:41 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/11 "2020-02-19T21:41:55Z")

</div>

Please paste what you have in your function node in a reply

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [20 February 2020 08:03 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/12 "2020-02-20T08:03:56Z")

</div>

I've made it simpler just to identify what's going wrong...

 ![Cattura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c5e96ccafa7ee1ccf793b7df3b6f76a07f217bd8.png)

And that's the EXCEL report:

[{"400":"550"}]

Bye

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 February 2020 08:46 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/13 "2020-02-20T08:46:07Z")

</div>

Please post an export of the full flow. Something is not right

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [20 February 2020 09:18 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/14 "2020-02-20T09:18:04Z")

</div>

Dear Paul,  
I appreciate what you're doing, but I think that if you propose a solution, and then I try it, and so on, we will not find a solution in a reasonable time.  
So I propose that yourself try the code and then, if found, post it.  
By the way, thanks for your spending time.  
Bye.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 February 2020 09:26 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/15 "2020-02-20T09:26:21Z")

</div>

The reason I’m asking for your flow is that I did try my solution before suggesting it and I get a different result so something is different.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 February 2020 09:52 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/16 "2020-02-20T09:52:01Z")

</div>

Here is the flow I've used to replicate your input data, the function node and it's output.

```auto
[{"id":"f95d0f7f.50a1","type":"inject","z":"9ba1ec76.07e4d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":80,"wires":[["177ecb03.83bef5"]]},{"id":"e0fb2f1d.5195d","type":"function","z":"9ba1ec76.07e4d8","name":"","func":"var z0 = msg.payload[2]\nvar z1 = msg.payload[3]\nvar d = new Date()\nvar t0 = d.getHours() \nvar t1 = d.getMinutes()\nif(t1<10){t1='0'+t1}\nvar t2 = d.getDate()\nvar t3 = d.getMonth() + 1\nvar t4 = d.getFullYear()\nvar t = t0+\":\"+t1\nvar tt = t2+\"/\"+t3+\"/\"+t4\nvar a = '';\na = z0 +\",\" + t +',' + tt + \"\\n\";\na += z1 +\",\" + t +',' + tt + \"\\n\";\nmsg.payload = a;\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":80,"wires":[["215c5afc.7e2b96"]]},{"id":"215c5afc.7e2b96","type":"debug","z":"9ba1ec76.07e4d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":80,"wires":[]},{"id":"177ecb03.83bef5","type":"function","z":"9ba1ec76.07e4d8","name":"","func":"msg.payload = []\nmsg.payload[0] = '200'\nmsg.payload[1] = '300'\nmsg.payload[2] = '400'\nmsg.payload[3] = '500'\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":80,"wires":[["e0fb2f1d.5195d","1c14e297.e5133d"]]},{"id":"1c14e297.e5133d","type":"debug","z":"9ba1ec76.07e4d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":160,"wires":[]}]

```

you might want to compare it to what you have coded

```auto
2/20/2020, 4:50:07 AMnode: 1c14e297.e5133d
msg.payload : array[4]
  ["200", "300", "400", "500"]

2/20/2020, 4:50:07 AMnode: 215c5afc.7e2b96
msg.payload : string[38]
string[38]
  400,9:50,20/2/2020
  500,9:50,20/2/2020

```

---

<div class="post-metadata">

**Author:** ![dathor](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dathor](https://discourse.nodered.org/u/dathor)\
**Post date:** [20 February 2020 10:12 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/17 "2020-02-20T10:12:36Z")

</div>

I cant comment on passing arrays to the CSV node but when i have used it passing it an object seemed to work fine. So in your case the payload would look something like...

`msg.payload = {'z0':z0,'z1':z1,'t':t,'tt',tt}`

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [20 February 2020 11:16 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/18 "2020-02-20T11:16:40Z")

</div>

Paul,  
I've copied your script as I've red:  
 ![Cattura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/9425338c316dfece013f9de9c06dfba2b951f0ab.png)  
Maybe I'm missing something, I'm just a noob...

---

<div class="post-metadata">

**Author:** ![frankzappa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frankzappa/32/19648_2.png) [@frankzappa](https://discourse.nodered.org/u/frankzappa)\
**Post date:** [20 February 2020 11:21 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/19 "2020-02-20T11:21:04Z")

</div>

Dathor,  
if I write like you say, the result will only exported into a unique box.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 February 2020 11:21 UTC](https://discourse.nodered.org/t/help-csv-node-issue/21983/20 "2020-02-20T11:21:42Z")

</div>

did you import the flow? Because somehow you now have escape characters in the lines with the 'slashes'. Just remove the backslashes.

🤔 I probably should have stuck with single quotes instead of using both single and double quotes

[Next page](https://discourse.nodered.org/t/help-csv-node-issue/21983.md?page=2)
