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

**URL:** <https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815>\
**Category:** General\
**Created:** [29 March 2020 07:35 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815 "2020-03-29T07:35:55Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![bug00](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@bug00](https://discourse.nodered.org/u/bug00)\
**Post date:** [29 March 2020 07:35 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/1 "2020-03-29T07:35:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 March 2020 07:38 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/2 "2020-03-29T07:38:28Z")

</div>

Post your flow (using the instructions from [this post](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)) and some sample data from your input file as we don't know what you are processing.

---

<div class="post-metadata">

**Author:** ![bug00](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@bug00](https://discourse.nodered.org/u/bug00)\
**Post date:** [29 March 2020 08:31 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/3 "2020-03-29T08:31:26Z")

</div>

Of course 🙂

```auto
[{"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](https://discourse.nodered.org/uploads/short-url/fKX9HgwGY1TdG59Lb5eSSAhJOv9.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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 March 2020 09:02 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/4 "2020-03-29T09:02:06Z")

</div>

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 ?

 ![Screenshot 2020-03-29 at 11.00.56](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0cf4819586ef84d94b2faaaec4c46036c1daca5b.jpeg)

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

---

<div class="post-metadata">

**Author:** ![bug00](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@bug00](https://discourse.nodered.org/u/bug00)\
**Post date:** [29 March 2020 09:16 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/5 "2020-03-29T09:16:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 March 2020 09:55 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/6 "2020-03-29T09:55:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [29 March 2020 10:47 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/7 "2020-03-29T10:47:29Z")

</div>

> [@bug00](#):
>
> I don't understand why with file in node, in "msg per line" configuration i loose every object on msg.

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 'change`node after the`file-in` ode to restore thoes valuse to the msg.

---

<div class="post-metadata">

**Author:** ![bug00](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@bug00](https://discourse.nodered.org/u/bug00)\
**Post date:** [29 March 2020 11:22 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/8 "2020-03-29T11:22:49Z")

</div>

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

```auto
[{"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 😕

Thank all for time past !

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [29 March 2020 12:20 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/9 "2020-03-29T12:20:53Z")

</div>

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

 ![Screen Shot 2020-03-29 at 8.12.37 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/d/4d6bac4610f64a87030c4724c3bf483cffe850ef.png)  
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.

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![bug00](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@bug00](https://discourse.nodered.org/u/bug00)\
**Post date:** [29 March 2020 13:41 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/10 "2020-03-29T13:41:27Z")

</div>

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

like this

```auto
[{"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 😕

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [29 March 2020 14:22 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/11 "2020-03-29T14:22:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bug00](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@bug00](https://discourse.nodered.org/u/bug00)\
**Post date:** [29 March 2020 14:26 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/12 "2020-03-29T14:26:43Z")

</div>

it's make sense ! Thank a lot !

---

<div class="post-metadata">

**Author:** ![bug00](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@bug00](https://discourse.nodered.org/u/bug00)\
**Post date:** [4 April 2020 05:52 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/13 "2020-04-04T05:52:00Z")

</div>

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

---

<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:** [3 June 2020 05:52 UTC](https://discourse.nodered.org/t/object-on-msg-deleted-after-file-in-node-msg-per-line-configuraton/23815/14 "2020-06-03T05:52:06Z")

</div>

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