# Add Single String to msg.payload so csv output prints as title of messages?

**URL:** https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355
**Category:** General
**Created:** [29 May 2024 12:46 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355 "2024-05-29T12:46:38Z")
**Posts on this page:** 8
**Page:** 2

<div class="post-metadata">

### Author: ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)
#### Post date: [5 June 2024 10:37 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355/21 "2024-06-05T10:37:09Z")

</div>

> [@marcus-j-davies](#):
>
> ```auto
> [{"id":"7bfc1276c35b6509","type":"tab","label":"CSV","disabled":false,"info":"","env":[]},{"id":"03c9c0616c672829","type":"inject","z":"7bfc1276c35b6509","name":"Start Batch","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":220,"wires":[["5e9222632ba1334e"]]},{"id":"4e5849be7752ca47","type":"comment","z":"7bfc1276c35b6509","name":"Replace with Start Button Pressed event","info":"","x":200,"y":180,"wires":[]},{"id":"ce9e5217f32843f8","type":"inject","z":"7bfc1276c35b6509","name":"Serial Row","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Value 1\tValue 2\tValue 3\tValue 4","payloadType":"str","x":120,"y":360,"wires":[["b3d3c7247052f86b"]]},{"id":"ce54001e098a57e6","type":"comment","z":"7bfc1276c35b6509","name":"Replace with serial input","info":"","x":150,"y":320,"wires":[]},{"id":"3ccc0f7cc0b78546","type":"change","z":"7bfc1276c35b6509","name":"","rules":[{"t":"set","p":"started","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":220,"wires":[["d492314b5a670940"]]},{"id":"5e9222632ba1334e","type":"switch","z":"7bfc1276c35b6509","name":"Not Started?","property":"started","propertyType":"flow","rules":[{"t":"false"},{"t":"null"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":220,"wires":[["3ccc0f7cc0b78546"],["3ccc0f7cc0b78546"]]},{"id":"795960c49f6c5518","type":"comment","z":"7bfc1276c35b6509","name":"Replace with Stop Button Pressed event","info":"","x":200,"y":460,"wires":[]},{"id":"ffcdcd5d59e8b750","type":"inject","z":"7bfc1276c35b6509","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":500,"wires":[["81c2379d0ea67134"]]},{"id":"81c2379d0ea67134","type":"change","z":"7bfc1276c35b6509","name":"","rules":[{"t":"set","p":"started","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":500,"wires":[[]]},{"id":"bf3167a5aa971165","type":"csv","z":"7bfc1276c35b6509","name":"","sep":"\\t","hdrin":"","hdrout":"none","multi":"one","ret":"\\r\\n","temp":"","skip":"0","strings":true,"include_empty_strings":true,"include_null_values":true,"x":590,"y":640,"wires":[["be18bb8c452ef282"]]},{"id":"be18bb8c452ef282","type":"file","z":"7bfc1276c35b6509","name":"","filename":"/Users/marcusdavies/Documents/Test.csv","filenameType":"str","appendNewline":false,"createDir":true,"overwriteFile":"false","encoding":"none","x":910,"y":640,"wires":[[]]},{"id":"368c0794da18eb4c","type":"inject","z":"7bfc1276c35b6509","name":"On Start Up","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":100,"wires":[["2afa3d1da87c5f3a"]]},{"id":"736f27152da7eb26","type":"link in","z":"7bfc1276c35b6509","name":"link in 1","links":["fcab9a3611ea143b","d72516572e8c2694","c847e5c58cde0c9b"],"x":65,"y":640,"wires":[["49412ebf550e8a93"]]},{"id":"fcab9a3611ea143b","type":"link out","z":"7bfc1276c35b6509","name":"link out 1","mode":"link","links":["736f27152da7eb26"],"x":635,"y":100,"wires":[]},{"id":"d72516572e8c2694","type":"link out","z":"7bfc1276c35b6509","name":"link out 2","mode":"link","links":["736f27152da7eb26"],"x":1115,"y":220,"wires":[]},{"id":"f0e01029efaf89fb","type":"comment","z":"7bfc1276c35b6509","name":"Sets the top level header when deployed","info":"","x":200,"y":60,"wires":[]},{"id":"d492314b5a670940","type":"function","z":"7bfc1276c35b6509","name":"Set Batch Header","func":"msg.payload = `${new Date()}\t\t\t\t`\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":220,"wires":[["d72516572e8c2694"]]},{"id":"c847e5c58cde0c9b","type":"link out","z":"7bfc1276c35b6509","name":"link out 3","mode":"link","links":["736f27152da7eb26"],"x":815,"y":360,"wires":[]},{"id":"c0899d814360eab8","type":"comment","z":"7bfc1276c35b6509","name":"Sink to CSV","info":"","x":110,"y":600,"wires":[]},{"id":"2afa3d1da87c5f3a","type":"function","z":"7bfc1276c35b6509","name":"Set File Header","func":"msg.payload = '2kV Test Readings\t\t\t\t'\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":100,"wires":[["fcab9a3611ea143b"]]},{"id":"06effc064c18e04b","type":"function","z":"7bfc1276c35b6509","name":"Pad Column","func":"msg.payload += '\t'\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":360,"wires":[["c847e5c58cde0c9b"]]},{"id":"49412ebf550e8a93","type":"function","z":"7bfc1276c35b6509","name":"Split to Columns","func":"msg.payload = msg.payload.split('\t')\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":640,"wires":[["bf3167a5aa971165"]]},{"id":"b3d3c7247052f86b","type":"switch","z":"7bfc1276c35b6509","name":"Started?","property":"started","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":360,"wires":[["06effc064c18e04b"]]}]
> 
> ```

ah i see, thats fair enough, to be honest i do infact want a tab before the first message of the readings to i've added it. i've done some jiggery pokery and using your flow to simulate it i've managed to get the values out as numbers with board names as CSV headers  
for your curiosity this is how i jigged yours:

```auto
[{"id":"7bfc1276c35b6509","type":"tab","label":"CSV","disabled":false,"info":"","env":[]},{"id":"03c9c0616c672829","type":"inject","z":"7bfc1276c35b6509","name":"Start Batch","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":220,"wires":[["5e9222632ba1334e"]]},{"id":"4e5849be7752ca47","type":"comment","z":"7bfc1276c35b6509","name":"Replace with Start Button Pressed event","info":"","x":200,"y":180,"wires":[]},{"id":"ce9e5217f32843f8","type":"inject","z":"7bfc1276c35b6509","name":"Serial Row","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1\t2\t3\t4","payloadType":"str","x":120,"y":360,"wires":[["b3d3c7247052f86b"]]},{"id":"ce54001e098a57e6","type":"comment","z":"7bfc1276c35b6509","name":"Replace with serial input","info":"","x":150,"y":320,"wires":[]},{"id":"3ccc0f7cc0b78546","type":"change","z":"7bfc1276c35b6509","name":"","rules":[{"t":"set","p":"started","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":220,"wires":[["d492314b5a670940"]]},{"id":"5e9222632ba1334e","type":"switch","z":"7bfc1276c35b6509","name":"Not Started?","property":"started","propertyType":"flow","rules":[{"t":"false"},{"t":"null"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":220,"wires":[["3ccc0f7cc0b78546"],["3ccc0f7cc0b78546"]]},{"id":"795960c49f6c5518","type":"comment","z":"7bfc1276c35b6509","name":"Replace with Stop Button Pressed event","info":"","x":200,"y":460,"wires":[]},{"id":"ffcdcd5d59e8b750","type":"inject","z":"7bfc1276c35b6509","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":500,"wires":[["81c2379d0ea67134"]]},{"id":"81c2379d0ea67134","type":"change","z":"7bfc1276c35b6509","name":"","rules":[{"t":"set","p":"started","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":500,"wires":[[]]},{"id":"bf3167a5aa971165","type":"csv","z":"7bfc1276c35b6509","name":"","sep":"\\t","hdrin":true,"hdrout":"all","multi":"one","ret":"\\n","temp":" ,Board 1, Board 2, Board 3, Board 4,","skip":"0","strings":true,"include_empty_strings":true,"include_null_values":true,"x":590,"y":640,"wires":[["be18bb8c452ef282","b17e46e1c13e1ab3"]]},{"id":"be18bb8c452ef282","type":"file","z":"7bfc1276c35b6509","name":"","filename":"C:\\Users\\223131446\\documents\\CSV.xls","filenameType":"str","appendNewline":false,"createDir":true,"overwriteFile":"false","encoding":"none","x":910,"y":640,"wires":[[]]},{"id":"368c0794da18eb4c","type":"inject","z":"7bfc1276c35b6509","name":"On Start Up","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":100,"wires":[["2afa3d1da87c5f3a"]]},{"id":"736f27152da7eb26","type":"link in","z":"7bfc1276c35b6509","name":"link in 1","links":["c847e5c58cde0c9b"],"x":65,"y":640,"wires":[["49412ebf550e8a93"]]},{"id":"fcab9a3611ea143b","type":"link out","z":"7bfc1276c35b6509","name":"link out 1","mode":"link","links":[],"x":635,"y":100,"wires":[]},{"id":"d72516572e8c2694","type":"link out","z":"7bfc1276c35b6509","name":"link out 2","mode":"link","links":[],"x":1115,"y":220,"wires":[]},{"id":"f0e01029efaf89fb","type":"comment","z":"7bfc1276c35b6509","name":"Sets the top level header when deployed","info":"","x":200,"y":60,"wires":[]},{"id":"d492314b5a670940","type":"function","z":"7bfc1276c35b6509","name":"Set Batch Header","func":"msg.payload = `${new Date()}` + '\\n'\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":200,"wires":[["d72516572e8c2694","be18bb8c452ef282"]]},{"id":"c847e5c58cde0c9b","type":"link out","z":"7bfc1276c35b6509","name":"link out 3","mode":"link","links":["736f27152da7eb26"],"x":815,"y":360,"wires":[]},{"id":"c0899d814360eab8","type":"comment","z":"7bfc1276c35b6509","name":"Sink to CSV","info":"","x":110,"y":600,"wires":[]},{"id":"2afa3d1da87c5f3a","type":"function","z":"7bfc1276c35b6509","name":"Set File Header","func":"msg.payload = '2kV Test Readings' + '\\n'\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":100,"wires":[["fcab9a3611ea143b","be18bb8c452ef282"]]},{"id":"06effc064c18e04b","type":"function","z":"7bfc1276c35b6509","name":"Pad Column","func":"msg.payload = '\t' + msg.payload\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":360,"wires":[["c847e5c58cde0c9b"]]},{"id":"49412ebf550e8a93","type":"function","z":"7bfc1276c35b6509","name":"Split to Columns","func":"msg.payload = msg.payload.split('\t')\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":640,"wires":[["bf3167a5aa971165"]]},{"id":"b3d3c7247052f86b","type":"switch","z":"7bfc1276c35b6509","name":"Started?","property":"started","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":360,"wires":[["06effc064c18e04b"]]},{"id":"b17e46e1c13e1ab3","type":"debug","z":"7bfc1276c35b6509","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1060,"y":520,"wires":[]}]

```

and it's allowed me to present the data in excel like this: which is near spot on!!!

 ![CSV WIN](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/560498458be69e0a1f81b11201446183c2a6658b.png)

with that i should be able to integrate it to the full flow that is taking the serial data 🙂 thanks again for your invaluable help marcus

---

<div class="post-metadata">

### Author: ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)
#### Post date: [5 June 2024 11:37 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355/22 "2024-06-05T11:37:40Z")

</div>

ah @marcus-j-davies i've attempted to integrate it to my automatic dataflow, but it's misbehaving because i want the time stamp not just once per start but once per reading. and CSV node doesn't like it for some reason

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 June 2024 11:52 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355/23 "2024-06-05T11:52:14Z")

</div>

Try replacing the code in the Pad Column block with the below.

```auto
msg.payload = `${new Date()}\n	${msg.payload}`
return msg;

```

---

<div class="post-metadata">

### Author: ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)
#### Post date: [5 June 2024 12:01 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355/24 "2024-06-05T12:01:11Z")

</div>

> [@marcus-j-davies](#):
>
> `${new Date()}\n	${msg.payload}`

yeah that's basically what i was doing with this:

> var timestamp = new Date().toString()+'\n';  
> msg.payload = timestamp +'\t '+ msg.payload;  
> return msg;

But this ends up being the output to excel:

 ![excel no new line](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/72dbbd8321182cb846dc9a03fa836b5943fa3273.png)

(i have also compared my pad column method to yours and i get same result btw)

currently trying to figure out a way to get the items in column to to effectively drop one row down... tricky stuff

---

<div class="post-metadata">

### Author: ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)
#### Post date: [5 June 2024 12:29 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355/25 "2024-06-05T12:29:17Z")

</div>

@marcus-j-davies GOOD NEWS! i figured out how to shift it all down 🙂 by duplicating my time sticker and placing the node AFTER the CSV node i now get this:

 ![IDEAL!](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/77ddf1b44815ecfbe0a93cedb4de5293b8bda7f7.png)

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 June 2024 12:48 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355/26 "2024-06-05T12:48:30Z")

</div>

Sorry - Got called away.

Nice work!!

---

<div class="post-metadata">

### Author: ![Boerwors](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Boerwors](https://discourse.nodered.org/u/Boerwors)
#### Post date: [5 June 2024 13:31 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355/27 "2024-06-05T13:31:10Z")

</div>

no worries, thank you again for your tutelage 😃

---

<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: [19 June 2024 13:31 UTC](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355/28 "2024-06-19T13:31:29Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/add-single-string-to-msg-payload-so-csv-output-prints-as-title-of-messages/88355.md?page=1)
