Don't want duplicate values in table - Need to know best practice

geet
Tera Guru

Hi All,

I have a table as follows:

find_real_file.png

I don't want duplicate values as follows:

find_real_file.png

I want to put a validation that user should not be able to submit the record if there is already a record with 2500 limit.

I want to know whether it will be a best practice to put validation as if there are 10,000 records with 2500 limit value, will it be going to impact my system performance.

Regards,

Shikha Khanna

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Shikha,



Are you saying you don't need duplicate values in the Limit column when the record is created by user?


If yes then have before insert business rule and query the same table with the value of limit field and if found use current.setAbortAction(true);



Script:



var gr = new GlideRecord('table_name');


gr.addQuery('limit',current.u_limit);


gr.query();


if(gr.next()){


gs.addInfoMessage('There is duplicate value for limit in the table');


current.setAbortAction(true);


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Karthik Reddy T
Kilo Sage

Hello Shikha,




Make the filed Subsidairy id field as unique.



Configure dictionary   on field and make the unique field as true.



By default unique is not   there add it from the sluchblucket of configure dictionary.


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

I dn't want to make subsidiary ID unique.


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Shikha,



Are you saying you don't need duplicate values in the Limit column when the record is created by user?


If yes then have before insert business rule and query the same table with the value of limit field and if found use current.setAbortAction(true);



Script:



var gr = new GlideRecord('table_name');


gr.addQuery('limit',current.u_limit);


gr.query();


if(gr.next()){


gs.addInfoMessage('There is duplicate value for limit in the table');


current.setAbortAction(true);


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I can try your solution but i want to query on the base of subsidiary ID and currency as follows:



find_real_file.png



Now user will put values


find_real_file.png



Now when user will try to submit this, then he should get error that for this subsidiary ID and currency, this limit already exist..