- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 01:24 AM
Hello Everyone,
I had a use case to restrict the creation of duplicate records on a table based on 3 fields.
1. Account
2. Assignment Grp
3. Trouble Type
If any records with these 3 field values existing on the table, system needs to alert the user ex. ''Record with similar combination existed''.
Can anyone help me to achieve this requirement?
Thanks,
Hari
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2022 09:40 PM
Hi,
you should write before insert business rule on the custom table and then query the table with these 3 fields
Note: Ensure you give correct field names here
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord(current.getTableName());
gr.addQuery("u_account", current.u_account); // give correct field name
gr.addQuery("u_trouble_type", current.u_trouble_type); // give correct field name
gr.addQuery("u_assignment_group", current.u_assignment_group); // give correct field name
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage("This is a duplicate record");
current.setAbortAction(true);
}
})(current, previous);
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-30-2022 04:36 AM
Hi suvro,
On which table should i need toi write that BR ?
I need to restrict on one of the custom created table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2022 09:34 PM
You should write this business rule on your custom table and in the script also glide on the same table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2022 09:40 PM
Hi,
you should write before insert business rule on the custom table and then query the table with these 3 fields
Note: Ensure you give correct field names here
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord(current.getTableName());
gr.addQuery("u_account", current.u_account); // give correct field name
gr.addQuery("u_trouble_type", current.u_trouble_type); // give correct field name
gr.addQuery("u_assignment_group", current.u_assignment_group); // give correct field name
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage("This is a duplicate record");
current.setAbortAction(true);
}
})(current, previous);
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
07-04-2022 12:24 AM
Hi Ankur,
It's working. Thank you
Regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 05:11 AM
Hey Ankur,
I have also same requirement but i want to restrict and notify the user on catalog item form that the request for this item already exist in an open state. I am using 2 fields i.e
asset tags and replacement checkbox field.
Could you please provide some assistance