duplicate check for multiple fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2020 10:37 PM
hello
i want to apply duplicate check for multiple fields in such a way if one field id is same for two fields then it will go for another three field checking and if these fields match then it will pop up a message for user already exist. Here i applied a bussiness rule where it is correctly working for one fields but when i apply code for another fields it takes values in the table with that also shows that invalid insert.Kindly give solution for this.
thanks
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2020 10:50 PM
Hi Kajal,
If combination of 2 or 3 fields should be unique then you can rather set them as unique at dictionary level
ServiceNow will out of the box show invalid insert
but if you are trying to do this using before insert business rule then is it not working? can you share the script here?
Mark ✅ Correct if this solves your issue and also mark 👍 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
01-22-2020 11:06 PM
The script is here.I applied this for scoped application.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var grAst = new GlideRecord('table_name');
grAst.addQuery('roll_number', current.roll_number);
grAst.addQuery('name', current.name);
grAst.addQuery('address', current.address);
grAst.addQuery('city', current.city);
//grAst.addQuery('country', current.country);
grAst.addQuery('postcode', current.postcode);
grAst.setLimit(1);
grAst.query();
if (grAst.hasNext() && grAst.sys_id == current.sys_id)
{
gs.addErrorMessage("Serial number already exists");
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2020 11:14 PM
Hi Kajal,
Is the table in the same scoped application
you can use abort action on the custom tables created as part of the scoped application(their own scope).
Mark ✅ Correct if this solves your issue and also mark 👍 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
01-23-2020 01:28 AM
yes table is in same scoped application.
abort action is not woriking.