Hi,
I am trying to write a few lines to a text file, but I want to rename the file to a unique name every time I write the lines into it. Is there a way I can do it?
Thank you in advance.
Kevin.
Hi,
I am trying to write a few lines to a text file, but I want to rename the file to a unique name every time I write the lines into it. Is there a way I can do it?
Thank you in advance.
Kevin.
What does the info sidebar for the file node say ?
Writes msg.payload to a file, either adding to the end or replacing the existing content. Alternatively, it can delete the file.
Inputs
filename string
If not configured in the node, this optional property sets the name of the file to be updated.
Output
On completion of write, input message is sent to output port.
Details
Each message payload will be added to the end of the file, optionally appending a newline (\n) character between each one.
If msg.filename is used the file will be closed after every write. For best performance use a fixed filename.
It can be configured to overwrite the entire file rather than append. For example, when writing binary data to a file, such as an image, this option should be used and the option to append a newline should be disabled.
Alternatively, this node can be configured to delete the file.
Anything that I am missing here?
No. That looks right.... so ... can you provide a msg.filename
property like it says ?
Ah.. Let me look into it. I am still new to node-red and also programming. Thank you for leading me in the right direction. Let me try and see what I can do.
hey @dceejay I tried to work on it a little bit but failed. I can see the right filename on the write file node but it does not add the contents of the file I am trying to send.
[{"id":"46fd0507.a3748c","type":"tab","label":"Pick up","disabled":false,"info":""},{"id":"cfa3d7dc.fbea48","type":"inject","z":"46fd0507.a3748c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":135,"y":50,"wires":[["ca052046.49e9a"]]},{"id":"ca052046.49e9a","type":"file in","z":"46fd0507.a3748c","name":"silheader","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silheader.txt","format":"utf8","chunk":false,"sendError":false,"x":335,"y":50,"wires":[["aa7d225.1c55fe"]]},{"id":"aa7d225.1c55fe","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":false,"createDir":false,"overwriteFile":"true","x":550,"y":50,"wires":[["dc8ff76f.6e6f38"]]},{"id":"dc8ff76f.6e6f38","type":"file in","z":"46fd0507.a3748c","name":"","filename":"C:\\\\storeman\\\\paymentscollected\\\\incometest.txt","format":"utf8","chunk":false,"sendError":false,"x":880,"y":50,"wires":[["6694e779.e5d978"]]},{"id":"9aca91c6.d20db","type":"xml","z":"46fd0507.a3748c","name":"BI1","property":"payload","attr":"","chr":"","x":1375,"y":50,"wires":[["1acb67b0.1e3fe8","c9c086e0.69fca8"]]},{"id":"c9c086e0.69fca8","type":"change","z":"46fd0507.a3748c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":180,"y":150,"wires":[["bd9dd308.bd518"]]},{"id":"bd9dd308.bd518","type":"MSSQL","z":"46fd0507.a3748c","mssqlCN":"3dfb67e2.c19788","name":"F1032","query":"Select F1032 from dbo.SYS_TAB","outField":"payload","x":400,"y":150,"wires":[["1bb506e0.b51d59"]]},{"id":"1bb506e0.b51d59","type":"csv","z":"46fd0507.a3748c","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"F1032","skip":"0","x":575,"y":150,"wires":[["973e8d95.5a19e"]]},{"id":"973e8d95.5a19e","type":"function","z":"46fd0507.a3748c","name":"storing seq","func":"var seq = msg.payload;\nflow.set(\"seqf\",seq);\nmsg.payload = seq.toString().padStart(8,\"0\");\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":150,"wires":[["120c3b88.71a1e4"]]},{"id":"120c3b88.71a1e4","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":false,"createDir":false,"overwriteFile":"false","x":975,"y":150,"wires":[["2a367610.19a9fa"]]},{"id":"2a367610.19a9fa","type":"change","z":"46fd0507.a3748c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"','770901','770901',,,","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1155,"y":150,"wires":[["e832c8d.41e2538"]]},{"id":"e832c8d.41e2538","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":false,"createDir":false,"overwriteFile":"false","x":1375,"y":150,"wires":[["cc449ee8.b74ce"]]},{"id":"cc449ee8.b74ce","type":"function","z":"46fd0507.a3748c","name":"setting date","func":"var now = Date.now();\nvar year = new Date().getUTCFullYear();\nvar year_start = Date.UTC(year, 0, 1);\nvar day_length_in_ms = 1000*60*60*24;\nvar day_number = Math.floor((now - year_start)/day_length_in_ms);\nday_number = day_number + 1; \nvar d = new Date();\nvar hr = d.getHours().toString().padStart(2,\"0\");\nvar mn = d.getMinutes().toString().padStart(2,\"0\")\nvar sec = d.getSeconds().toString().padStart(2,\"0\")\n//msg.payload = msg.payload.toString().padStart(3,\"0\")\nvar padday = day_number.toString().padStart(3,\"0\")\nvar yearr = year \nflow.set([\"yearf\",\"pdf\",\"hourf\",\"minf\",\"secf\"], [year,padday,hr,mn,sec]);\nvar all = { \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1545,"y":150,"wires":[["d5f35416.0c8928"]]},{"id":"c314c399.2061e","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":125,"y":225,"wires":[["69b69025.efe2f"]]},{"id":"d5f35416.0c8928","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"'{{payload.year}}{{payload.pd}}','{{payload.hour}}{{payload.min}}{{payload.second}}','{{payload.year}}{{payload.pd}}','{{payload.hour}}{{payload.min}}',,'ADD','BALANCING',,,,,,'1/1.0','V2.0',,,);\n\n","output":"str","x":1735,"y":150,"wires":[["c314c399.2061e","59921556.7f373c"]]},{"id":"69b69025.efe2f","type":"change","z":"46fd0507.a3748c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":225,"wires":[["e1b628c1.e38758"]]},{"id":"e1b628c1.e38758","type":"file in","z":"46fd0507.a3748c","name":"silmid","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silmid.txt","format":"utf8","chunk":false,"sendError":false,"x":525,"y":225,"wires":[["c61c71bb.bdf42"]]},{"id":"c61c71bb.bdf42","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":false,"createDir":false,"overwriteFile":"false","x":750,"y":225,"wires":[["41ac9ac6.62b484"]]},{"id":"41ac9ac6.62b484","type":"file in","z":"46fd0507.a3748c","name":"incoming","filename":"C:\\\\storeman\\\\paymentscollected\\\\incometest.txt","format":"utf8","chunk":false,"sendError":false,"x":935,"y":225,"wires":[["91f7ce9b.dd37d"]]},{"id":"91f7ce9b.dd37d","type":"xml","z":"46fd0507.a3748c","name":"BI","property":"payload","attr":"","chr":"","x":450,"y":400,"wires":[["8b3b6175.93649","8f0db1d6.f9d1a"]]},{"id":"5672b70c.fca3f8","type":"function","z":"46fd0507.a3748c","name":"val4","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\nvar tdr = Number(tdr) - 100;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"));\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":600,"wires":[["6b692a54.e7a374"]]},{"id":"f776038c.48c8f","type":"debug","z":"46fd0507.a3748c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1820,"y":625,"wires":[]},{"id":"b26cc2a5.2fe39","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},FIN,1,{{payload.tender}},0,0,1,{{payload.amount}},0,),","output":"str","x":1310,"y":450,"wires":[["64382fc2.c72ba"]]},{"id":"9676e171.fab7e","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},FIN,1,{{payload.tender}},0,0,1,{{payload.amount}},0,),","output":"str","x":1310,"y":500,"wires":[["f056fd5b.dd8eb"]]},{"id":"d7366de6.8181c","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},FIN,1,{{payload.tender}},0,0,1,{{payload.amount}},0,),","output":"str","x":1310,"y":550,"wires":[["c46720a0.4f094"]]},{"id":"6b692a54.e7a374","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},FIN,1,{{payload.tender}},0,0,-1,-{{payload.amount}},0,),","output":"str","x":1310,"y":600,"wires":[["e58f1da3.9825c"]]},{"id":"17c4c758.1ff8d9","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},FIN,1,{{payload.tender}},0,0,-1,-{{payload.amount}},0,),","output":"str","x":1310,"y":650,"wires":[["fe541fbf.7a10c"]]},{"id":"ed504724.0dd898","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},CLK,{{payload.tids}},{{payload.tender}},0,0,1,{{payload.amount}},0,),","output":"str","x":1310,"y":700,"wires":[["c5dc57bc.48d488"]]},{"id":"e76e7e3c.0d97f","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},CLK,{{payload.tids}},{{payload.tender}},0,0,-1,-{{payload.amount}},0,),","output":"str","x":1310,"y":750,"wires":[["7f874888.9eb3a8"]]},{"id":"895b6b07.415308","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},CLK,{{payload.tids}},{{payload.tender}},0,0,-1,-{{payload.amount}},0,),","output":"str","x":1310,"y":800,"wires":[["7defaf8f.ebeb6"]]},{"id":"64382fc2.c72ba","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1450,"y":450,"wires":[["f776038c.48c8f"]]},{"id":"f056fd5b.dd8eb","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1450,"y":500,"wires":[["f776038c.48c8f"]]},{"id":"c46720a0.4f094","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1450,"y":550,"wires":[["f776038c.48c8f"]]},{"id":"e58f1da3.9825c","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1452.857177734375,"y":600,"wires":[["f776038c.48c8f"]]},{"id":"fe541fbf.7a10c","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1450,"y":650,"wires":[["f776038c.48c8f"]]},{"id":"c5dc57bc.48d488","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1450,"y":700,"wires":[["f776038c.48c8f"]]},{"id":"7f874888.9eb3a8","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1450,"y":750,"wires":[["f776038c.48c8f"]]},{"id":"7defaf8f.ebeb6","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1452.857177734375,"y":800,"wires":[["f776038c.48c8f"]]},{"id":"3ef5662d.79bb4a","type":"function","z":"46fd0507.a3748c","name":"val1","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\nvar tdr = Number(tdr) - 200;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"))\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":450,"wires":[["b26cc2a5.2fe39"]]},{"id":"9a8de771.97e328","type":"function","z":"46fd0507.a3748c","name":"val2","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\nvar tdr = Number(tdr) + 1000;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"));\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":500,"wires":[["9676e171.fab7e"]]},{"id":"f2c99ead.6fd23","type":"function","z":"46fd0507.a3748c","name":"val3","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\nvar tdr = Number(tdr) + 1100;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"));\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":550,"wires":[["d7366de6.8181c"]]},{"id":"8b817bc7.feea88","type":"function","z":"46fd0507.a3748c","name":"val8","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"));\nvar tid = Number(flow.get(\"tidf\"));\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn, \"tids\" : tid};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":800,"wires":[["895b6b07.415308"]]},{"id":"483ff663.a61f18","type":"function","z":"46fd0507.a3748c","name":"val5","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"));\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":650,"wires":[["17c4c758.1ff8d9"]]},{"id":"57c39129.a336f","type":"function","z":"46fd0507.a3748c","name":"val6","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\nvar tdr = Number(tdr) - 200;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"));\nvar tid = Number(flow.get(\"tidf\"));\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn, \"tids\" : tid};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":700,"wires":[["ed504724.0dd898"]]},{"id":"af603f.a561cfc","type":"function","z":"46fd0507.a3748c","name":"val7","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\nvar tdr = Number(tdr) - 100;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"));\nvar tid = Number(flow.get(\"tidf\"));\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn, \"tids\" : tid};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":750,"wires":[["e76e7e3c.0d97f"]]},{"id":"44ec60d3.4658e","type":"MSSQL","z":"46fd0507.a3748c","mssqlCN":"3dfb67e2.c19788","name":"sequence number","query":"Select F1185 from dbo.clk_tab where F1126 = {{{payload}}}","outField":"payload","x":1315,"y":400,"wires":[["d9e8ba24.383528"]]},{"id":"8f0db1d6.f9d1a","type":"function","z":"46fd0507.a3748c","name":"send seq","func":"//var count = context.get('count')||0;\nmsg.payload = msg.payload.VeriBalancePlatformPOSLog.Transaction[0].WorkstationID[0];\nreturn msg;","outputs":1,"noerr":0,"x":1135,"y":400,"wires":[["44ec60d3.4658e"]]},{"id":"d9e8ba24.383528","type":"csv","z":"46fd0507.a3748c","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"F1185","skip":"0","x":1500,"y":400,"wires":[["d97e059f.582188"]]},{"id":"d97e059f.582188","type":"function","z":"46fd0507.a3748c","name":"transaction ID","func":"var count = context.get('count')||0;\ncount = count + 1;\ncontext.set('count',count);\ntid = msg.payload;\nflow.set(\"tidf\",tid);\nmsg.payload = count;\nreturn msg;","outputs":1,"noerr":0,"x":1680,"y":400,"wires":[["9419c927.4aa688"]]},{"id":"1acb67b0.1e3fe8","type":"function","z":"46fd0507.a3748c","name":"finding length","func":"var len = msg.payload.VeriBalancePlatformPOSLog.Transaction[0].TenderControlTransaction[0].TillSettle[0].TenderSummary.length;\nflow.set(\"lenten\",len);\n//msg.payload = lenten;\n//return msg;","outputs":1,"noerr":0,"x":1720,"y":50,"wires":[["bc25f85a.3afb48"]]},{"id":"9419c927.4aa688","type":"debug","z":"46fd0507.a3748c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1895,"y":400,"wires":[]},{"id":"8b3b6175.93649","type":"function","z":"46fd0507.a3748c","name":"values","func":"var ts = msg.payload.VeriBalancePlatformPOSLog.Transaction[0].TenderControlTransaction[0].TillSettle[0].TenderSummary;\nvar len=ts.length;\nze = 0;\n\nfor (var z=0;z<len;z++)\n{\nvar tdr = ts[z].Ending[0].$.TenderType;\nvar amt = ts[z].Ending[0].Amount[0]._.toString().slice(1);\ntdr = Number(tdr);\n\nvar all = { \"length\" : len, \"tender\" : tdr, \"amount\" : amt};\nvar ze = ze + 1;\nnode.send({\"payload\" : { \"length\" : len, \"tender\" : tdr, \"amount\" : amt, \"last\" : ze}});\n}","outputs":1,"noerr":0,"x":500,"y":600,"wires":[["6e6ef7c1.b4d598"]]},{"id":"6e6ef7c1.b4d598","type":"delay","z":"46fd0507.a3748c","name":"","pauseType":"rate","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"3","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":805,"y":600,"wires":[["3ef5662d.79bb4a","9a8de771.97e328","f2c99ead.6fd23","5672b70c.fca3f8","483ff663.a61f18","57c39129.a336f","af603f.a561cfc","9744964e.c02e78"]]},{"id":"59921556.7f373c","type":"change","z":"46fd0507.a3748c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1455,"y":250,"wires":[["b1e04617.ab7148"]]},{"id":"b1e04617.ab7148","type":"MSSQL","z":"46fd0507.a3748c","mssqlCN":"3dfb67e2.c19788","name":"F1032 add","query":"Update dbo.SYS_TAB\nSet F1032 = F1032+1","outField":"payload","x":1695,"y":250,"wires":[[]]},{"id":"9744964e.c02e78","type":"switch","z":"46fd0507.a3748c","name":"","property":"payload.last","propertyType":"msg","rules":[{"t":"eq","v":"payload.length","vt":"msg"},{"t":"neq","v":"0","vt":"msg"}],"checkall":"false","repair":false,"outputs":2,"x":950,"y":825,"wires":[["d5bfbad2.55f068"],["8b817bc7.feea88"]]},{"id":"d5bfbad2.55f068","type":"function","z":"46fd0507.a3748c","name":"last","func":"var len = msg.payload.lenght;\nvar tdr = msg.payload.tender;\nvar amt = msg.payload.amount;\n//flow.set([\"lenf\",\"tenderf\",\"amountf\"], [len,tdr,amt]);\nvar hr = flow.get(\"hourf\");\nvar mn = flow.get(\"minf\");\nvar sec = flow.get(\"secf\");\nvar padday = flow.get(\"pdf\");\nvar yearr = flow.get(\"yearf\");\nvar seqn = Number(flow.get(\"seqf\"));\nvar tid = Number(flow.get(\"tidf\"));\nvar cn = msg.payload.last;\nvar all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt, \"year\" : yearr, \"pd\" : padday, \"hour\" : hr, \"min\" : mn, \"second\" : sec, \"seq\" : seqn, \"coun\" : cn, \"tids\" : tid};\n//var all = { \"lenght\" : len, \"tender\" : tdr, \"amount\" : amt};\nmsg.payload = all;\nreturn msg;","outputs":1,"noerr":0,"x":1125,"y":850,"wires":[["f79b4220.68a79"]]},{"id":"f79b4220.68a79","type":"template","z":"46fd0507.a3748c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"(770,901,{{payload.year}}{{payload.pd}},{{payload.hour}}{{payload.min}}{{payload.second}},T,{{payload.seq}},{{payload.coun}},CLK,{{payload.tids}},{{payload.tender}},0,0,-1,-{{payload.amount}},0,);","output":"str","x":1310,"y":850,"wires":[["e9804f97.5fcc4"]]},{"id":"e9804f97.5fcc4","type":"file","z":"46fd0507.a3748c","name":"silfinal","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1452.857177734375,"y":850,"wires":[["f776038c.48c8f","748bd590.798a9c"]]},{"id":"bc25f85a.3afb48","type":"debug","z":"46fd0507.a3748c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1945,"y":50,"wires":[]},{"id":"6694e779.e5d978","type":"switch","z":"46fd0507.a3748c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Ending TenderType","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1175,"y":50,"wires":[["9aca91c6.d20db"],[]]},{"id":"748bd590.798a9c","type":"change","z":"46fd0507.a3748c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1205,"y":975,"wires":[["ce6d40df.75098"]]},{"id":"ce6d40df.75098","type":"switch","z":"46fd0507.a3748c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"cont","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1375,"y":975,"wires":[["70714117.16062"],["ff3b1278.039f1"]]},{"id":"70714117.16062","type":"function","z":"46fd0507.a3748c","name":"last","func":"var seqn = Number(flow.get(\"seqf\"));\nvar tid = Number(flow.get(\"tidf\"));\nvar tempString1 = \"C:\\\\storeman\\\\fake901\";\nvar tempString2 = tempString1.concat(seqn);\nvar finalPath = tempString2.concat(\".bipu\");\nmsg.filename=finalPath;\nreturn msg;","outputs":1,"noerr":0,"x":1600,"y":950,"wires":[["93966e6d.fd72a"]]},{"id":"ff3b1278.039f1","type":"file in","z":"46fd0507.a3748c","name":"","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","format":"utf8","chunk":false,"sendError":false,"x":1575,"y":1050,"wires":[["93966e6d.fd72a"]]},{"id":"93966e6d.fd72a","type":"file","z":"46fd0507.a3748c","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"false","x":1850,"y":975,"wires":[["48f55a26.0c3294"]]},{"id":"48f55a26.0c3294","type":"debug","z":"46fd0507.a3748c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1920,"y":875,"wires":[]},{"id":"3dfb67e2.c19788","type":"MSSQL-CN","z":"","name":"Dev","server":"KEVINWORK\\SQLEXPRESS","encyption":false,"database":"STORESQL"}]
The last few nodes towards the end. I tried adding a delay to add contents of the file but that did not seem to work.
Any suggestions? Thank you.
That's a rather large flow - which bit are we looking at ? where is the filename created and the payload created ?
I thought I should have added a picture in the reply but here it is. The highlighted part is what I tried.
The set msg.payload currently sets it to blank so it writes an empty file
If I set that to something it seem to write a file ok. I set the flows variables to fixed values to make it work for me - I assume you are setting them elsewhere ok...
This is my cut down version
[{"id":"bdbe3bc9.463358","type":"inject","z":"303828a7.eae0d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":200,"wires":[["ddaeeca8.9bb97"]]},{"id":"ddaeeca8.9bb97","type":"change","z":"303828a7.eae0d8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Hello World","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":365,"y":210,"wires":[["247e0cae.bd8a94"]]},{"id":"247e0cae.bd8a94","type":"switch","z":"303828a7.eae0d8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"cont","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":535,"y":210,"wires":[["e8015423.bb9028","23ceba1e.5bbb26"],["fa86fa6d.f902c8"]]},{"id":"e8015423.bb9028","type":"function","z":"303828a7.eae0d8","name":"last","func":"var seqn = 100;\nvar tid = 999;\nvar tempString1 = \"C:\\\\storeman\\\\fake901\";\nvar tempString2 = tempString1.concat(seqn);\nvar finalPath = tempString2.concat(\".bipu\");\nmsg.filename=finalPath;\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":185,"wires":[["592c7897.fe92c8","61911c4b.e073a4"]]},{"id":"fa86fa6d.f902c8","type":"file in","z":"303828a7.eae0d8","name":"","filename":"C:\\\\storeman\\\\paymentscollected\\\\inbound\\\\silfinal.txt","format":"utf8","chunk":false,"sendError":false,"x":735,"y":285,"wires":[["592c7897.fe92c8"]]},{"id":"23ceba1e.5bbb26","type":"debug","z":"303828a7.eae0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":140,"wires":[]},{"id":"592c7897.fe92c8","type":"file","z":"303828a7.eae0d8","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"false","x":1010,"y":210,"wires":[["27e60909.71ce56"]]},{"id":"61911c4b.e073a4","type":"debug","z":"303828a7.eae0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":850,"y":240,"wires":[]},{"id":"27e60909.71ce56","type":"debug","z":"303828a7.eae0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1080,"y":110,"wires":[]}]
Thank you,
However I am not able to read a local file and send it to the newly created file,
[{"id":"bf2d9616.a40018","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"c600318d.c405b","type":"change","z":"bf2d9616.a40018","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":305,"y":850,"wires":[["e93d5266.8a821"]]},{"id":"e93d5266.8a821","type":"switch","z":"bf2d9616.a40018","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"cont","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":850,"wires":[["6c3ed086.9b0ac"],["5838218f.0ad29"]]},{"id":"6c3ed086.9b0ac","type":"function","z":"bf2d9616.a40018","name":"last","func":"var seqn = Number(flow.get(\"seqf\"));\nvar tid = Number(flow.get(\"tidf\"));\nvar tempString1 = \"C:\\\\storeman\\\\fake901\\\\\";\nvar tempString2 = tempString1.concat(seqn);\nvar finalPath = tempString2.concat(\".bipu\");\nmsg.filename=finalPath;\nreturn msg;","outputs":1,"noerr":0,"x":775,"y":850,"wires":[["42e192e3.1b66ac"]]},{"id":"5ff07fb6.878f1","type":"file in","z":"bf2d9616.a40018","name":"add a local text file","filename":"add a local text file","format":"utf8","chunk":false,"sendError":false,"x":1140,"y":925,"wires":[["42e192e3.1b66ac"]]},{"id":"42e192e3.1b66ac","type":"file","z":"bf2d9616.a40018","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"false","x":1375,"y":850,"wires":[["dde87982.154c18"]]},{"id":"dde87982.154c18","type":"debug","z":"bf2d9616.a40018","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1670,"y":850,"wires":[]},{"id":"5838218f.0ad29","type":"delay","z":"bf2d9616.a40018","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":895,"y":925,"wires":[["5ff07fb6.878f1"]]}]
If you look in the flow and maybe add a local text file from your machine and try to write it to the newly created file? I end up with a empty file.
1: is what is being written in the new file
2: is the file being read and the same content I want to write to new file
PS: I realized I forgot to add \ after fake901 folder.. I was not looking the right folder.
the long file read node - when it outputs the file - also sets its own msg.filename to the name of the file read so can't just be fed to the file out node. You should feed it instead through the function node to set the filename to the new one.
(and feed the delay node from the switch rather than the function to prevent a loop)
Ah, that explains why nothing is being written to the new file. However, I am still confused as to how I would feed through the function node like you mentioned
would you be able to help me with an example maybe?
I really appreciate all the help. Thank you so much.
Kevin.
based on the snippet you pasted 2 posts above...
[{"id":"10266d89.758d62","type":"change","z":"85f3395f.e89138","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":305,"y":850,"wires":[["71f91261.1f773c"]]},{"id":"71f91261.1f773c","type":"switch","z":"85f3395f.e89138","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"cont","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":850,"wires":[["511fca62.2feb24"],["937092f0.59bc1"]]},{"id":"511fca62.2feb24","type":"function","z":"85f3395f.e89138","name":"last","func":"var seqn = Number(flow.get(\"seqf\"));\nvar tid = Number(flow.get(\"tidf\"));\nvar tempString1 = \"C:\\\\storeman\\\\fake901\\\\\";\nvar tempString2 = tempString1.concat(seqn);\nvar finalPath = tempString2.concat(\".bipu\");\nmsg.filename=finalPath;\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":840,"wires":[["ccb0048d.d88c28"]]},{"id":"937092f0.59bc1","type":"delay","z":"85f3395f.e89138","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":750,"y":940,"wires":[["db7d15f7.5c3e08"]]},{"id":"ccb0048d.d88c28","type":"file","z":"85f3395f.e89138","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"false","x":1230,"y":840,"wires":[["28367280.ce9b2e"]]},{"id":"db7d15f7.5c3e08","type":"file in","z":"85f3395f.e89138","name":"add a local text file","filename":"add a local text file","format":"utf8","chunk":false,"sendError":false,"x":970,"y":940,"wires":[["511fca62.2feb24"]]},{"id":"28367280.ce9b2e","type":"debug","z":"85f3395f.e89138","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1410,"y":840,"wires":[]}]
Great! That worked. I assumed once the msg.payload is passed through a function node, it would over-write whatever was in the previous node. Thank you again for all the help.
depends how you handle things in the function node... ideally you should just add/modify the properties in the msg that you need to and leave all others alone... and that is exactly what you are doing... well done !