Require unique value on a field

carlh
Kilo Guru

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

1 ACCEPTED SOLUTION

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);


}


View solution in original post

11 REPLIES 11

Glad you got your question answered


devi_putra
Kilo Guru

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.


$4B2212656FA0F0AC.jpg


$7511B459FE8D8DE8.jpg



Hope this will help you.



Thanks,


Devi



PS: Hit like, Helpful or Correct depending on the impact of the response.


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).

devi_putra
Kilo Guru

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.


Abhinay Erra
Giga Sage

Please mark my response as correct