# Return only Ids that have not been checked

**URL:** <https://discourse.nodered.org/t/return-only-ids-that-have-not-been-checked/75713>\
**Category:** General\
**Tags:** function-node\
**Created:** [24 February 2023 21:11 UTC](https://discourse.nodered.org/t/return-only-ids-that-have-not-been-checked/75713 "2023-02-24T21:11:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgoics](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@sgoics](https://discourse.nodered.org/u/sgoics)\
**Post date:** [24 February 2023 21:11 UTC](https://discourse.nodered.org/t/return-only-ids-that-have-not-been-checked/75713/1 "2023-02-24T21:11:14Z")

</div>

Hi again!  
I have a flow that when ran, checks for a certain string from a table via mssql, then spits the alert out in the form of an email. That all works fine. However, I don't want it to keep sending out the same one. Each string also has a unique ID associated with it. So, I would like for it to check for this UID, if it's already sent an alert on it, then ignore, if it's new, then send the alert. Any thoughts for accomplishing this?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [25 February 2023 00:10 UTC](https://discourse.nodered.org/t/return-only-ids-that-have-not-been-checked/75713/2 "2023-02-25T00:10:30Z")

</div>

Use a filter node?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [25 February 2023 01:13 UTC](https://discourse.nodered.org/t/return-only-ids-that-have-not-been-checked/75713/3 "2023-02-25T01:13:39Z")

</div>

Put a date time field "alerted"in the database table and update it after you sent the alert?

---

<div class="post-metadata">

**Author:** ![znetsixe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/znetsixe/32/72588_2.png) [@znetsixe](https://discourse.nodered.org/u/znetsixe)\
**Post date:** [26 February 2023 07:23 UTC](https://discourse.nodered.org/t/return-only-ids-that-have-not-been-checked/75713/4 "2023-02-26T07:23:52Z")

</div>

If you are sequential all you need is a function node with a context var that stores the last id you sent out. Then do an if statement to check if its equal to the last one and if not overwrite it again with the new value.  
For example:

**On node start tab :**

```auto
context.set("prev_id",0);

```

**On node msg:**

```auto
prev_id = context.get("prev_id");
curr_id = msg.payload;

If(prev_id != curr_id){
//mail stuff
context.set("prev_id",curr_id);
Return msg;
}

```

---

<div class="post-metadata">

**Author:** ![sgoics](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@sgoics](https://discourse.nodered.org/u/sgoics)\
**Post date:** [27 February 2023 18:29 UTC](https://discourse.nodered.org/t/return-only-ids-that-have-not-been-checked/75713/5 "2023-02-27T18:29:41Z")

</div>

Thanks znetsixe, that works!

---

<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:** [28 April 2023 18:30 UTC](https://discourse.nodered.org/t/return-only-ids-that-have-not-been-checked/75713/6 "2023-04-28T18:30:34Z")

</div>

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