CSV format issues

wow thankyou for this.
I have read through it and it all makes sense to me, BUT! its outputting the below to the 'new' file; seems to be populating the same value for Origin, and WorkOrderNo from the last file in the source data.... not sure why though... is it doing this for you or did I mess something up somehow?

image

I've tried to debug it but it all seems to make sense.
I've tried adding a switch (after 'check that userid is not null') to make sure the flow.WorkOrderNo and payload.WorkOrderNo match... but this meant it outputted only the last file... correctly! but only the last one...

Oops, the first row should have gone to to two places and little delay needs to be added, try this.

[{"id":"cf8b7d5f.f10d4","type":"tab","label":"Add UserId to Work Order row","disabled":false,"info":""},{"id":"986390a6.1fc008","type":"inject","z":"cf8b7d5f.f10d4","name":"Put path to input file here","props":[{"p":"filename","v":"/Users/Paul/Downloads/example_data.txt","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":40,"wires":[["5894fa73.245dc4"]]},{"id":"5894fa73.245dc4","type":"file in","z":"cf8b7d5f.f10d4","name":"Read CSV file","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":180,"y":100,"wires":[["d3decaa3.9f1b78"]]},{"id":"d3decaa3.9f1b78","type":"csv","z":"cf8b7d5f.f10d4","name":"Split CSV file by row","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":200,"y":160,"wires":[["6429ae45.cf8fa"]]},{"id":"62fd6fee.b6bab8","type":"switch","z":"cf8b7d5f.f10d4","name":"If 'payload.Name' not empty, save it, else pass along","property":"payload.Name","propertyType":"msg","rules":[{"t":"nempty"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":320,"wires":[["77f9962e.a2f718"],["a2d67aa3.683d88"]]},{"id":"a2d67aa3.683d88","type":"switch","z":"cf8b7d5f.f10d4","name":"if UserId not null send it on","property":"payload.UserId","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":220,"y":380,"wires":[["3593269b.31609a"]]},{"id":"3593269b.31609a","type":"change","z":"cf8b7d5f.f10d4","name":"Build row from flow variable and add in UserId","rules":[{"t":"set","p":"UserId","pt":"msg","to":"payload.UserId","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.Name","pt":"msg","to":"payload.Name","tot":"flow"},{"t":"set","p":"payload.OriginType","pt":"msg","to":"payload.OriginType","tot":"flow"},{"t":"set","p":"payload.UserId","pt":"msg","to":"UserId","tot":"msg"},{"t":"set","p":"payload.WorkOrderNo","pt":"msg","to":"payload.WorkOrderNo","tot":"flow"},{"t":"set","p":"payload.EstimatedHours","pt":"msg","to":"payload.EstimatedHours","tot":"flow"},{"t":"set","p":"payload.City","pt":"msg","to":"payload.City","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":440,"wires":[["81d70889.bb934"]]},{"id":"c6c120da.974438","type":"switch","z":"cf8b7d5f.f10d4","name":"Send first row (column names) to new file","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":240,"y":240,"wires":[["3967749d.d0d7fc","62fd6fee.b6bab8"],["62fd6fee.b6bab8"]]},{"id":"c3149b6c.0b752","type":"file","z":"cf8b7d5f.f10d4","name":"Write column header row to new file","filename":"/Users/Paul/tmp/new.csv","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":690,"y":260,"wires":[[]]},{"id":"ec3898c5.dd1a4","type":"file","z":"cf8b7d5f.f10d4","name":"Write column data row to new file","filename":"/Users/Paul/tmp/new.csv","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":240,"y":580,"wires":[["ad22918e.26a72"]]},{"id":"81d70889.bb934","type":"csv","z":"cf8b7d5f.f10d4","name":"convert object to CSV string","sep":",","hdrin":false,"hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":220,"y":500,"wires":[["ec3898c5.dd1a4"]]},{"id":"3967749d.d0d7fc","type":"change","z":"cf8b7d5f.f10d4","name":"move columns to payload","rules":[{"t":"move","p":"columns","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"count","pt":"flow","to":"parts.count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":180,"wires":[["c3149b6c.0b752"]]},{"id":"2a88095.8d777f6","type":"comment","z":"cf8b7d5f.f10d4","name":"Change the filename to point to the full path of output file","info":"","x":750,"y":220,"wires":[]},{"id":"77f9962e.a2f718","type":"change","z":"cf8b7d5f.f10d4","name":"Save W/O info to flow context","rules":[{"t":"set","p":"payload","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":320,"wires":[[]]},{"id":"3c8f1acf.951fbe","type":"comment","z":"cf8b7d5f.f10d4","name":"Change the filename to point to the full path of output file","info":"","x":310,"y":540,"wires":[]},{"id":"ad22918e.26a72","type":"debug","z":"cf8b7d5f.f10d4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":170,"y":640,"wires":[]},{"id":"f522a18b.0f3178","type":"trigger","z":"cf8b7d5f.f10d4","name":"","op1":"1","op2":"0","op1type":"val","op2type":"val","duration":"250","extend":"false","overrideDelay":"false","units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":590,"y":80,"wires":[[]]},{"id":"6429ae45.cf8fa","type":"delay","z":"cf8b7d5f.f10d4","name":"limit 1 msg/.05s","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"0.05","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":180,"y":200,"wires":[["c6c120da.974438"]]}]
1 Like

Hey Thanks a lot for this.
It actually seems simple enough now that I can look at the flow, and I understand the logic of it all now.
I just couldn't make it work in my head before in one flow using the nodes!

good solution, thanks again.

I will use this to tweak it a bit to fit in my existing flows etc, and make sure I can re-build it and fully understand how it works.

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