Help - CSV node issue

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.

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

Forgot my EXCEL function...

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

msg.payload : array[0]
[ empty ]

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

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

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

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

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


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

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

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


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

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

And that's the EXCEL report:



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

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.

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.

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

[{"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

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]

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}

I've copied your script as I've red:
Maybe I'm missing something, I'm just a noob...

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

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

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