# Allow only last msg.payload to pass

**URL:** <https://discourse.nodered.org/t/allow-only-last-msg-payload-to-pass/44810>\
**Category:** General\
**Created:** [27 April 2021 14:40 UTC](https://discourse.nodered.org/t/allow-only-last-msg-payload-to-pass/44810 "2021-04-27T14:40:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sahsha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahsha/32/43845_2.png) [@sahsha](https://discourse.nodered.org/u/sahsha)\
**Post date:** [27 April 2021 14:40 UTC](https://discourse.nodered.org/t/allow-only-last-msg-payload-to-pass/44810/1 "2021-04-27T14:40:23Z")

</div>

Hi everyone, I need help with on how to allow only the last msg.payload to pass.  
I've made a flow to send email and email is comprised of data from different flows which are executed at different time and when all the values are joined then only the mail should pass.  
But when 1st flow is injected then only 1st data is send through mail  
and when 2nd flow is executed then 2nd data is send through mail  
.........  
and goes on till all flows are executed.

So need to send the last msg through the email node in a given amount of time.  
for eg:- out of the messages accumulated in 01 or 02 minute the last one to be passed through.

my flow:

```auto
[{"id":"69af16d9.734a88","type":"function","z":"1f149e22.43a482","name":"","func":"var lastMsg = context.get(\"lastMsg\");\ncontext.set(\"lastMsg\", msg.payload);\nmsg.topic='MT-2 Small Shed Node-Red Notification';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":960,"y":240,"wires":[["5bdff2c1.b0268c","2cbd67d3.08ad08"]]},{"id":"ce1afe70.2f059","type":"template","z":"1f149e22.43a482","name":"%","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Hello! This is an auto generated test mail from Node Red.\nOEE for MT-2's Small Shed for the {{payload.datetime}} is observed to be {{payload.oee}} %\nwhere\nAvailability = {{payload.a}} %\nPerformance = {{payload.p}} %\nQuality = {{payload.q}} %","output":"str","x":810,"y":240,"wires":[["69af16d9.734a88"]]},{"id":"fc5c18be.c8f568","type":"debug","z":"1f149e22.43a482","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1570,"y":260,"wires":[]},{"id":"d18fea82.1dba68","type":"join","z":"1f149e22.43a482","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":670,"y":240,"wires":[["ce1afe70.2f059","56707d56.474b64"]]},{"id":"3f0a8b74.bd1244","type":"link in","z":"1f149e22.43a482","name":"Input - OEE date/time email","links":["efb30cd1.5d77e"],"x":135,"y":240,"wires":[["cd9a8ca.439d47"]]},{"id":"cd9a8ca.439d47","type":"simpletime","z":"1f149e22.43a482","name":"","mydate":true,"myymd":true,"myyear":true,"mymonth":true,"mymonthn":true,"mydom":true,"mydoy":true,"myday":true,"myhourpm":true,"myhour":true,"mytime":true,"mytimes":true,"myminute":true,"myminutes":true,"mysecond":true,"mymillis":true,"myepoch":true,"myrawdate":true,"mypm":true,"x":250,"y":240,"wires":[["1fb4ae59.af7362"]]},{"id":"1fb4ae59.af7362","type":"template","z":"1f149e22.43a482","name":"date","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"date {{mydom}}-{{mymonth}}-{{myyear}} and time {{myhourpm}}:{{myminute}} {{mypm}}","output":"str","x":390,"y":240,"wires":[["c038fda6.ebac"]]},{"id":"c038fda6.ebac","type":"function","z":"1f149e22.43a482","name":"","func":"msg.payload = msg.payload;\nmsg.topic='datetime';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":520,"y":240,"wires":[["d18fea82.1dba68"]]},{"id":"f114097a.cfaad8","type":"link in","z":"1f149e22.43a482","name":"Input - OEE email","links":["a49d3423.240e58"],"x":135,"y":280,"wires":[["d18fea82.1dba68"]]},{"id":"32806990.a05a56","type":"comment","z":"1f149e22.43a482","name":"Current Day OEE","info":"","x":230,"y":180,"wires":[]},{"id":"6c613165.c9a2","type":"link in","z":"1f149e22.43a482","name":"","links":["c5835b42.9f11a8","57f5fe29.8f7a3"],"x":135,"y":320,"wires":[["1125d0d4.6ac02f"]]},{"id":"f8dd9d38.b1c87","type":"link in","z":"1f149e22.43a482","name":"","links":["6aca116c.521d7","7320206e.48c73"],"x":135,"y":360,"wires":[["31a1e4be.cdf59c"]]},{"id":"1a968725.a7c989","type":"link in","z":"1f149e22.43a482","name":"","links":["188f2c56.784df4","8e094f56.2afd7"],"x":135,"y":400,"wires":[["5bde3dde.dfbd34"]]},{"id":"56707d56.474b64","type":"debug","z":"1f149e22.43a482","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":280,"wires":[]},{"id":"1125d0d4.6ac02f","type":"function","z":"1f149e22.43a482","name":"","func":"msg.payload = Number(msg.payload);;\nmsg.topic='a';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":320,"wires":[["d18fea82.1dba68"]]},{"id":"31a1e4be.cdf59c","type":"function","z":"1f149e22.43a482","name":"","func":"msg.payload = Number(msg.payload);;\nmsg.topic='p';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":360,"wires":[["d18fea82.1dba68"]]},{"id":"5bde3dde.dfbd34","type":"function","z":"1f149e22.43a482","name":"","func":"msg.payload = Number(msg.payload);;\nmsg.topic='q';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":400,"wires":[["d18fea82.1dba68"]]},{"id":"5bdff2c1.b0268c","type":"throttle","z":"1f149e22.43a482","name":"","throttleType":"reset","timeLimit":"10","timeLimitType":"seconds","countLimit":0,"blockSize":0,"locked":false,"x":1390,"y":240,"wires":[["fc5c18be.c8f568","7086b183.c65d6"]]},{"id":"2cbd67d3.08ad08","type":"function","z":"1f149e22.43a482","name":"reset","func":"msg.payload = msg.reset;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1110,"y":280,"wires":[["fa27de08.0943a"]]},{"id":"fa27de08.0943a","type":"delay","z":"1f149e22.43a482","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1240,"y":280,"wires":[["5bdff2c1.b0268c"]]},{"id":"7086b183.c65d6","type":"e-mail","z":"1f149e22.43a482","server":"","port":"","secure":false,"tls":true,"name":"","dname":"","x":1550,"y":220,"wires":[]}]

```

---

<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:** [26 June 2021 14:41 UTC](https://discourse.nodered.org/t/allow-only-last-msg-payload-to-pass/44810/2 "2021-06-26T14:41:04Z")

</div>

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