- 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 09:08 AM
Write a before insert business rule and put this script in there
var gr= new GlideRecord('core_company');
gr.addQuery('u_vndr_id',current.u_vndr_id);
gr.query();
if(gr.hasNext()){
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 09:18 AM
Nice! . Could we also add in a message stating "Vendor ID Already exists" when a match is found?

- 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:32 AM