# Perspective - Not Allowing Duplicate Entries Into a Table Component

**URL:** <https://forum.inductiveautomation.com/t/perspective-not-allowing-duplicate-entries-into-a-table-component/86962>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 7, 2024, 12:40pm UTC](https://forum.inductiveautomation.com/t/perspective-not-allowing-duplicate-entries-into-a-table-component/86962 "2024-03-07T12:40:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evan\_Medeiros](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@Evan\_Medeiros](https://forum.inductiveautomation.com/u/Evan_Medeiros)\
**Post date:** [March 7, 2024, 12:40pm UTC](https://forum.inductiveautomation.com/t/perspective-not-allowing-duplicate-entries-into-a-table-component/86962/1 "2024-03-07T12:40:12Z")

</div>

I have a table component that populates with database data when a barcode is scanned; currently how it works is when you scan a barcode it queries a row of data out of a database and creates a row with the found data and the barcode inside this table component. Currently in order to not allow the same part to be scanned into this table twice I am storing previousBarcode 1, 2, & 3 (The table wont exceed 4 rows) and comparing the new barcode with each of these variables every time. This seems unsophisticated so my question is: How when a barcode is scanned can I search the barcode column within the table component to see if there is a identical barcode?

Note: This all takes place within a message handler script that gets triggered once a barcode is scanned.

Thanks for your time!

---

<div class="post-metadata">

**Author:** ![Hayden\_Watson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hayden_watson/32/48792_2.png) [@Hayden\_Watson](https://forum.inductiveautomation.com/u/Hayden_Watson)\
**Post date:** [March 7, 2024, 2:48pm UTC](https://forum.inductiveautomation.com/t/perspective-not-allowing-duplicate-entries-into-a-table-component/86962/2 "2024-03-07T14:48:22Z")

</div>

If you're a database to store previous barcode scans, can you make a named query that just checks the database for the barcode ID. If it returns a value, it's a duplicate and you can make somekind of error popup.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 7, 2024, 2:56pm UTC](https://forum.inductiveautomation.com/t/perspective-not-allowing-duplicate-entries-into-a-table-component/86962/3 "2024-03-07T14:56:37Z")

</div>

The unsophisticaed and best way to ensure uniqueness in a database table - make the desired column(s) your primary key, or, since Ignition doesn't return non-int's nicely yet for getKey, put a `UNIQUE INDEX` on your column [SQL CREATE UNIQUE INDEX](https://www.w3schools.com/sql/sql_ref_create_unique_index.asp).

Then you can follow the pythonic paradigm of try first ask for forgiveness later. Try to insert, in the event the database throws you an error that you're violating the uniqueness constraint, then handle that.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 7, 2024, 3:14pm UTC](https://forum.inductiveautomation.com/t/perspective-not-allowing-duplicate-entries-into-a-table-component/86962/4 "2024-03-07T15:14:15Z")

</div>

> [@bkarabinchak.psi](#):
>
> since Ignition doesn't return non-int's nicely yet for getKey

_Psssst! system.db.runPrepInsert()_

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934/89):
>
> Automation Professionals is pleased to announce a new release of the Integration Toolkit module. This release adds one new scripting function, [system.db.runPrepInsert()](https://www.automation-pros.com/toolkit/doc/utility.html#runprepinsert). It is very similar to IA's [system.db.runPrepUpdate()](https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepUpdate), intepreting the query, args, database, and tx arguments in the same fashion. The getKey argument is omitted as moot, as this function always retrieves generated keys. The skipAudit optional argument is unimplemented. For Ignition v8.1+: [v2.0.15.240431913](https://www.automation-pros.com/ignition/Integration%20Toolkit-2.0.15.240431913-v81.modl) Do note the docu…

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 7, 2024, 6:22pm UTC](https://forum.inductiveautomation.com/t/perspective-not-allowing-duplicate-entries-into-a-table-component/86962/5 "2024-03-07T18:22:08Z")

</div>

Oh very nice, I'll have to upgrade! This alone is worth the update for me.
