- 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 01:33 AM
u can write a before business rule which will check with the values on the table. if it finds simliar values do an alert and and prevent it from inserting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2022 01:01 AM
Hi RC,
I do have only one table. On which table i need to write this BR and which table should i need to glide ?
Thanks,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 01:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 01:47 AM
You can write the below before insert business rule
Ensure correct field names
var tgr = new GlideRecord('your table name');
tgr.addquery('account', current.account);
tgr.addquery('assignment_group', current.assignment_group);
tgr.addquery('trouble_type', current.trouble_type);
tgr.query();
if (tgr.next()){
gs.addErrorMessage(" This record already exists");
current.setAbortAction(true);
}