- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2017 04:11 AM
Hi All,
I have a table as follows:
I don't want duplicate values as follows:
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2017 04:18 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2017 04:23 AM
Hi Shikha,
You can make the field value unique by clicking on the unique check box on the dictionarr entry of that record, however it will result in data loss, since you have mentioned already duplicate values are there.
Try to create Before Insert business rule, to check the field and give info to the user that there is already a record with same value.
Creating New Fields - ServiceNow Wiki
Below BR is similar for making the duplicate number prevention, however you can use the same just by modifying the field name with number field
var curNum = current.limit+ '';
if(curNum) {
var recordClass = current.getRecordClassName();
var gr = new GlideRecord(recordClass);
gr.addQuery('limit', curNum);
gr.query();
if(gr.getRowCount() > 0) {
gs.addInfoMessage("Limit was already available, please select a different limit.);
current.setAbortAction(true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2017 04:00 AM
HI Shikha
can u pls try this in business rule
(function executeRule(current, previous /*null when async*/) {
var Matching = new GlideRecord('table');
if(Matching.get('subsidary_id', current.subsidary_id)) {
gs.addErrorMessage(gs.getMessage("same record already exists."));
current.setAbortAction(true);
}
})(current, previous);
I hope this will helpful to u