- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 09:02 AM
Good morning.
How can I set up a field to query the table for unique values before allowing me to save a record to the table?
I wasn't sure how to word it but here's what I am doing. We are creating new vendors and need to check and make sure the "VendorID" field is not already in the table.
I'm hoping I can do this as a client script so it can be caught while on the form and fixed.
Could someone provide a script?
Table "core_company"
Field Name: "u_vndr_id" (string)
I have several field where I could use this as well so hoping it's as easy as changing the table and fields.
Thanks!!! Carl
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 09:23 AM
Sure, here you go
var gr= new GlideRecord('core_company');
gr.addQuery('u_vndr_id',current.u_vndr_id);
gr.query();
if(gr.hasNext()){
gs.addErrorMessage('Vendor ID Already exists');
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 10:45 AM
Glad you got your question answered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 09:29 AM
Hi Carl,
You can make the required field as Unique by checking the Unique check box from Dictionary Entry of that field.
Example: "User ID" field on User table is a Unique field.
Hope this will help you.
Thanks,
Devi
PS: Hit like, Helpful or Correct depending on the impact of the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 08:04 AM
This is not valid for me.
When I check Unique on my table and click on Save (or Update), it just unchecks it automatically.
However, the script from abhinay worked for me.
I did this on a customized table (extended from Task table).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 10:20 AM
Hi Carl,
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this discussion from your "inbox", use the "mark as correct" option under actions. If you are viewing it directly from the thread use the Correct Answer link (red with a star).
Thank you,
Devi.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 10:21 AM
Please mark my response as correct