- 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-28-2017 11:55 PM
Hi Ankur,
I have implemented your solution as follows, but i need to understand 1 thing.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('x_mkgaa_credit_car_credit_card_limit_calculation');
gr.addQuery('u_subsiary_id', current.u_subsiary_id);
gr.addQuery('u_currency', current.u_currency);
gr.addQuery('u_limit', current.u_limit);
gr.query();
if(gr.next())
{
gs.addErrorMessage(current.u_limit+' Limit already exist for this subsidiary and currency. Please put a different limit value');
current.setAbortAction(true);
current.u_limit ='';
}
})(current, previous);
Que: Right now i have only 12 records and gliding only 12 records will not affect my instance performance. What if i have 100000 records and i am gliding limit for all these records. Would it affect my instance performance?
Regards,
Shikha Khanna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2017 12:16 AM
Hi Shikha,
See if Unique index on fields will help you. From the comments above it seems like you want combination of two fields unique (subsidiary ID and currency). This can be guaranteed by unique index on subsidiary ID and currency. Means combination of values will be unique.
http://wiki.servicenow.com/index.php?title=Unique_Index#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2017 03:48 AM
Hi Shikha,
Any update on this? Can you mark my answer as correct, helpful and hit like if you were able to achieve your requirement. This helps in removing this question from unanswered list and helps others to search similar question quicker. Thanks in advance.
Regards
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
‎06-21-2017 08:31 AM
Done: Thanx for always helping 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2019 12:07 PM
I tried this and even though I don't have a duplicate and it does not create the record, I still get an error.
findDupeCircuitID();
function findDupeCircuitID() {
var gr = new GlideRecord("u_network_circuit");
gr.addQuery("u_ciruit_id", current.u_ciruit_id);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage("Circuit ID already exists");
current.setAbortAction(true);
}
}
It's on a Before Business rule.
Any thoughts?
Lisa