Object on msg deleted after file in node, msg per line configuraton

Hi,

I don't understand why with file in node, in "msg per line" configuration i loose every object on msg.

If if add a change node with a key msg : { test : 'toto' } then, after the file in node msg is totaly replace by file in node.

How i can retrieve this information ? I can attach object to flow context, but it available for all flow in workspace...

Any idea ?

Thank

Post your flow (using the instructions from this post) and some sample data from your input file as we don't know what you are processing.

Of course :slight_smile:

[{"id":"65232798.8b134","type":"inject","z":"a4b3c610.95e97","name":"inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":150,"y":1200,"wires":[["71097ee.c18278"]]},{"id":"bdce24b6.ce99c8","type":"debug","z":"a4b3c610.95e97","name":"filenameOut and test here ?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1120,"y":1200,"wires":[]},{"id":"71097ee.c18278","type":"change","z":"a4b3c610.95e97","name":"InitVar","rules":[{"t":"set","p":"test","pt":"msg","to":"Always here after file in split line ?","tot":"str"},{"t":"set","p":"filenameOut","pt":"msg","to":"T:\\test.txt","tot":"str"},{"t":"set","p":"filename","pt":"msg","to":"T:\\test.txt","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":1200,"wires":[["e57f4b3a.55d6c8"]]},{"id":"e57f4b3a.55d6c8","type":"file in","z":"a4b3c610.95e97","name":"read file line by line","filename":"","format":"lines","chunk":false,"sendError":false,"encoding":"none","x":440,"y":1200,"wires":[["f41b2d8e.e6b388"]]},{"id":"f41b2d8e.e6b388","type":"function","z":"a4b3c610.95e97","name":"Rupture process","func":"let cpt = context.get(\"cpt\") || 1\nlet pile = (context.get(\"pile\") || '')\nlet previousDate = context.get(\"previousDate\") || ''\n///const date = msg.payload.substring(7,8)\n\n//node.error(msg.parts.index)\nconst rupture = msg.conditionRupture ? msg.conditionRupture(msg) : true\nconst nbrLignesMax = flow.get(\"nbrLignesMax\") || -1\nif (rupture && (cpt > flow.get(\"nbrLignesMax\"))) {\n    //rupture\n    context.set(\"pile\", msg.payload)\n    context.set(\"cpt\", 2)\n    msg.payload = pile\n    \n    //here msg.filenameOut is undefined !\n    msg.filename=msg.filenameOut.replace(/(\\..{3})$/,new Date().getTime()+'\\$1')\n    return msg\n}else{\n    //node.error(msg.parts.index)\n    }\n\ncontext.set(\"cpt\", cpt + 1)\ncontext.set(\"pile\", pile + msg.payload)\n//context.set(\"previousDate\",date)","outputs":1,"noerr":0,"x":670,"y":1200,"wires":[["ad383501.85d998","18aeaf28.2741a1"]]},{"id":"ad383501.85d998","type":"file","z":"a4b3c610.95e97","name":"Save file","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":880,"y":1200,"wires":[["bdce24b6.ce99c8"]]},{"id":"18aeaf28.2741a1","type":"debug","z":"a4b3c610.95e97","name":"filenameOut and test here ?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":960,"y":1320,"wires":[]}]

Sample data : gros fichier a decouper - Copie.txt (1.5 KB)

I think into loop msg is overwrite ... if configure file in node in "a single utf8 string" abnd i use split, after join i retrieve object attached to msg before the file in node

Thank

I am not sure what you are trying to accomplish, but isn't it easier to use a csv node to get everything into an array ?

If you add column names, you will get objects with descriptive properties.

The goal is to slice a big file (200k lines) into many little file (10k lines) but we need to break after 10k lines AND if the date is not same that date of previous line

Definitively if i configure file in node in "single utf8 string" and after i split, alright, i add every object previously attach to msg, but if i configure in "msg per line" i loose every object previously attach to msg.

It sounds like you need a database after which you can query the data directly ? Just a suggestion.

I beleive this is because it has to create a new msg object for each line. You can see this by looking at the _msgid going into the file-in node and the _msgid coming out.

Should each msg coming out be a duplicate of the original msg except for msg.payload is the question.

For now I would suggest adding a change node before the file-in node to put the things you need into a flow variable and then putting another 'changenode after thefile-in` ode to restore thoes valuse to the msg.

I used flow before file-in, but flow wouldn't work like i excepted...

Flow is share over the tab... But i would a context share for currently linked node, not all flow on the tab

If you look this short example

[{"id":"4b2dfa51.db100c","type":"inject","z":"151e869a.bd19e9","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":190,"y":3940,"wires":[["4dc2d715.6a0f7"]]},{"id":"19806ce7.9856a3","type":"inject","z":"151e869a.bd19e9","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":190,"y":4020,"wires":[["4a042274.4e84fc"]]},{"id":"4dc2d715.6a0f7","type":"change","z":"151e869a.bd19e9","name":"","rules":[{"t":"set","p":"test","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":3960,"wires":[["de48e9cd.5f895"]]},{"id":"de48e9cd.5f895","type":"change","z":"151e869a.bd19e9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"test","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":3960,"wires":[["521566da.7fab28"]]},{"id":"521566da.7fab28","type":"debug","z":"151e869a.bd19e9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":840,"y":3940,"wires":[]},{"id":"4a042274.4e84fc","type":"change","z":"151e869a.bd19e9","name":"","rules":[{"t":"set","p":"test","pt":"flow","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":4020,"wires":[["64095740.a477f"]]},{"id":"64095740.a477f","type":"change","z":"151e869a.bd19e9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"test","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":4020,"wires":[["50384a8e.5b6d24"]]},{"id":"50384a8e.5b6d24","type":"debug","z":"151e869a.bd19e9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":840,"y":4000,"wires":[]}]

i would like for first flow 1 on debug and for the second flow 2.
But like we can see flow context is share for the 2. And if injector is activate a second times before the first time finish, the flow context is the same.

I would like a context who work like message indeed :confused:

Thank all for time past !

Saving msg.test, msg.filename and msg.filenameOut before the file-in and restoring after the file-in node gives me this


so you can see it works in the original situation. You should use unique variable names - even make them an object
flow.filein1.test
flow.filein1.filename
flow.filein1.filenameOut
so not to confuse them with other areas you use flow variables.

[{"id":"350973d5.d449ec","type":"inject","z":"63bc0d40.ad20cc","name":"inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":110,"y":60,"wires":[["8bcef677.9ca2b","200bed65.5b5d62"]]},{"id":"8bcef677.9ca2b","type":"change","z":"63bc0d40.ad20cc","name":"InitVar","rules":[{"t":"set","p":"test","pt":"msg","to":"Always here after file in split line ?","tot":"str"},{"t":"set","p":"filenameOut","pt":"msg","to":"/Users/Paul/tmp/Copie.txt","tot":"str"},{"t":"set","p":"filename","pt":"msg","to":"/Users/Paul/tmp/Copie.txt","tot":"str"},{"t":"set","p":"filein1.test","pt":"flow","to":"test","tot":"msg"},{"t":"set","p":"filein1.filenameOut","pt":"flow","to":"filenameOut","tot":"msg"},{"t":"set","p":"filein1.filename","pt":"flow","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":120,"wires":[["c31e5474.aea27","d9f2b582.34ab68"]]},{"id":"d9f2b582.34ab68","type":"file in","z":"63bc0d40.ad20cc","name":"read file line by line","filename":"","format":"lines","chunk":false,"sendError":false,"encoding":"none","x":150,"y":180,"wires":[["979d7dd6.6f3db8"]]},{"id":"3f18da.3e8c5726","type":"debug","z":"63bc0d40.ad20cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":390,"y":240,"wires":[]},{"id":"c31e5474.aea27","type":"debug","z":"63bc0d40.ad20cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":390,"y":120,"wires":[]},{"id":"200bed65.5b5d62","type":"debug","z":"63bc0d40.ad20cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":390,"y":60,"wires":[]},{"id":"979d7dd6.6f3db8","type":"change","z":"63bc0d40.ad20cc","name":"InitVar","rules":[{"t":"set","p":"test","pt":"msg","to":"filein1.test","tot":"flow"},{"t":"set","p":"filenameOut","pt":"msg","to":"filein1.filenameOut","tot":"flow"},{"t":"set","p":"filename","pt":"msg","to":"filein1.filename","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":240,"wires":[["3f18da.3e8c5726"]]}]

Good idea namespaced flox but i had more than one injector (and init var)

like this

[{"id":"93baac88.93e0c8","type":"inject","z":"4daa3bfe.444f64","name":"inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":150,"y":200,"wires":[["a75b40ee.b3d8d"]]},{"id":"a75b40ee.b3d8d","type":"change","z":"4daa3bfe.444f64","name":"InitVar","rules":[{"t":"set","p":"test","pt":"msg","to":"Always here after file in split line ?","tot":"str"},{"t":"set","p":"filenameOut","pt":"msg","to":"/Users/Paul/tmp/Copie.txt","tot":"str"},{"t":"set","p":"filename","pt":"msg","to":"/Users/Paul/tmp/Copie.txt","tot":"str"},{"t":"set","p":"filein1.test","pt":"flow","to":"test","tot":"msg"},{"t":"set","p":"filein1.filenameOut","pt":"flow","to":"filenameOut","tot":"msg"},{"t":"set","p":"filein1.filename","pt":"flow","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":200,"wires":[["567dbc58.34381c"]]},{"id":"567dbc58.34381c","type":"file in","z":"4daa3bfe.444f64","name":"read file line by line","filename":"","format":"lines","chunk":false,"sendError":false,"encoding":"none","x":640,"y":220,"wires":[["5b21af6f.8ee888"]]},{"id":"26dcd6fe.337772","type":"debug","z":"4daa3bfe.444f64","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":360,"wires":[]},{"id":"5b21af6f.8ee888","type":"change","z":"4daa3bfe.444f64","name":"InitVar","rules":[{"t":"set","p":"test","pt":"msg","to":"filein1.test","tot":"flow"},{"t":"set","p":"filenameOut","pt":"msg","to":"filein1.filenameOut","tot":"flow"},{"t":"set","p":"filename","pt":"msg","to":"filein1.filename","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":300,"wires":[["26dcd6fe.337772"]]},{"id":"efe1a927.16e25","type":"inject","z":"4daa3bfe.444f64","name":"inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":150,"y":280,"wires":[["fcee7aef.a1b36"]]},{"id":"fcee7aef.a1b36","type":"change","z":"4daa3bfe.444f64","name":"InitVar","rules":[{"t":"set","p":"test","pt":"msg","to":"Always here after file in split line ?","tot":"str"},{"t":"set","p":"filenameOut","pt":"msg","to":"/Users/Paul/tmp/Copie.txt","tot":"str"},{"t":"set","p":"filename","pt":"msg","to":"/Users/Paul/tmp/Copie.txt","tot":"str"},{"t":"set","p":"filein1.test","pt":"flow","to":"test","tot":"msg"},{"t":"set","p":"filein1.filenameOut","pt":"flow","to":"filenameOut","tot":"msg"},{"t":"set","p":"filein1.filename","pt":"flow","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":280,"wires":[["567dbc58.34381c"]]}]

So flow will be change by an injector while other flow is running :confused:

How many injectors will you have?
Will each injector read/write to a different file?

If so use the filename as the first level of the flow object. Then after the file-in node, extract the file name from msg.filename and use that name in the restoring of items in the msg

it's make sense ! Thank a lot !

Solve, issue from zenofmud is good, but i preferred use topic, who is preserve (even for a buffer read)

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