How to delete the "Return key" Character from Payload

How to delete the "Return key" Character from Payload when loading a file and using the join node as well.

Im trying to use the File Node with the Join Node to get a payload that isn't split in separate lines.

Bildschirmfoto 2020-02-14 um 14.59.20

[{"id":"c87373dc.38749","type":"random","z":"7aa3d45d.c5e5ec","name":"","low":"1","high":"3","inte":"true","property":"payload","x":2660,"y":2820,"wires":[["4c4be365.68b49c"]]},{"id":"4c4be365.68b49c","type":"switch","z":"7aa3d45d.c5e5ec","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":2810,"y":2800,"wires":[["32cab76e.b200f8"],["cffd8963.29c6b8"],["2e3cdfa6.e9012"]]},{"id":"32cab76e.b200f8","type":"change","z":"7aa3d45d.c5e5ec","name":"TCA Station - Arkham:","rules":[{"t":"set","p":"payload","pt":"msg","to":"TCA Station - Arkham:","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3040,"y":2760,"wires":[["a98bece5.703f5"]]},{"id":"cffd8963.29c6b8","type":"change","z":"7aa3d45d.c5e5ec","name":"The Code Agency - Station Arkham:","rules":[{"t":"set","p":"payload","pt":"msg","to":"The Code Agency - Station Arkham:","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3090,"y":2800,"wires":[["a98bece5.703f5"]]},{"id":"2e3cdfa6.e9012","type":"change","z":"7aa3d45d.c5e5ec","name":"Station Arkham der TCA:","rules":[{"t":"set","p":"payload","pt":"msg","to":"Station Arkham der TCA:","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3050,"y":2840,"wires":[["a98bece5.703f5"]]},{"id":"617f4b02.1b5b04","type":"change","z":"7aa3d45d.c5e5ec","name":" Missionen gestartet seit 01.01.2020","rules":[{"t":"set","p":"payload","pt":"msg","to":" Missionen gestartet seit 01.01.2020","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3080,"y":2960,"wires":[["a98bece5.703f5"]]},{"id":"ba782fea.bcc1b","type":"delay","z":"7aa3d45d.c5e5ec","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2660,"y":2980,"wires":[["617f4b02.1b5b04"]]},{"id":"a98bece5.703f5","type":"delay","z":"7aa3d45d.c5e5ec","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":3650,"y":2940,"wires":[["70d44552.ca2bec"]]},{"id":"8533392d.fcb4a8","type":"delay","z":"7aa3d45d.c5e5ec","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2170,"y":2900,"wires":[["c87373dc.38749","ba782fea.bcc1b","fb2d5faf.300ad"]]},{"id":"fb2d5faf.300ad","type":"file in","z":"7aa3d45d.c5e5ec","name":"","filename":"CounterGesamt","format":"","chunk":false,"sendError":false,"encoding":"none","x":3080,"y":2900,"wires":[["a98bece5.703f5"]]},{"id":"c11b317e.49b66","type":"schedex","z":"7aa3d45d.c5e5ec","name":"","suspended":false,"lat":"51.5135872","lon":"7.465298","ontime":"14:39","ontopic":"","onpayload":"go","onoffset":0,"onrandomoffset":0,"offtime":"14:40","offtopic":"","offpayload":"","offoffset":0,"offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":1830,"y":2900,"wires":[["f0ce5f95.ff8a7"]]},{"id":"f0ce5f95.ff8a7","type":"switch","z":"7aa3d45d.c5e5ec","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"go","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1990,"y":2900,"wires":[["8533392d.fcb4a8"],[]]},{"id":"2907f632.7bf81a","type":"inject","z":"7aa3d45d.c5e5ec","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1920,"y":2800,"wires":[["8533392d.fcb4a8"]]},{"id":"70d44552.ca2bec","type":"join","z":"7aa3d45d.c5e5ec","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"3","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":3690,"y":1980,"wires":[["15432b2.0e060d5"]]},{"id":"15432b2.0e060d5","type":"delay","z":"7aa3d45d.c5e5ec","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":4040,"y":1980,"wires":[["3c386c9c.340f04"]]},{"id":"3c386c9c.340f04","type":"debug","z":"7aa3d45d.c5e5ec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":4290,"y":1960,"wires":[]}]

Use a function with

msg.payload = msg.payload.trim();
return msg;
  • Screen shot

  • Example flow
[{"id":"ec0854f6.f57268","type":"inject","z":"15abe000.b52c7","name":"","topic":"","payload":"test","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":200,"wires":[["c3070426.a4bcd8"]]},{"id":"c3070426.a4bcd8","type":"function","z":"15abe000.b52c7","name":"add \\n","func":"msg.payload = msg.payload + '\\n';\n\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":280,"wires":[["583a8de1.7e4464","6b56e289.47f4ec"]]},{"id":"6b56e289.47f4ec","type":"function","z":"15abe000.b52c7","name":"trim()","func":"msg.payload = msg.payload.trim();\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":340,"wires":[["cafbcff3.6476a"]]},{"id":"583a8de1.7e4464","type":"debug","z":"15abe000.b52c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":780,"y":220,"wires":[]},{"id":"cafbcff3.6476a","type":"debug","z":"15abe000.b52c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":780,"y":300,"wires":[]}]

Trim doesn't work with loading a file. so it seems. get this error

function : (error)

"TypeError: Cannot read property 'trim' of undefined"

Trim doesn't work with loading a file. so it seems. get this error

I am not sure to understand.

The example node I provided works fine with me. I double-checked it.

Yes and no, somehow it won't work when using the file node to retrieve a number. But i found the error in the file write node was the option add new line checkt -__- but i will keep your script in mind works well on other things. thanks so much for the fast response and help man !

Just to explain why @rei_vilo's suggestion didn't work for you... String.trim() removes whitespace (including newlines) from the beginning or end of a string. It doesn't remove whitespace from the middle of a String which is what your screenshot shows you have.

You could use String.replace instead:

msg.payload = msg.payload.replace(/\n/g," ");
return msg;
1 Like

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