How to Block Duplicate Record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago - last edited 4 hours ago
The best way is create a Business Rule > before > insert
See an example of code
var dup = new GlideRecord('u_course_registration');
dup.addQuery('u_requested_for', current.u_requested_for);
dup.addQuery('u_course', current.u_course);
dup.addQuery('u_date', current.u_date);
dup.query();
if (dup.next()) {
gs.addErrorMessage('You have already requested this course on this date.');
current.setAbortAction(true); // If true, will be aborted the record producer creation
}
This is an example, kindly send the names of fields from the form to give an code more correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
By writing a Before Business Rule on the target table that queries for an existing record matching the user, course and date, and if found aborts the insert (for example by using current.setAbortAction(true) or setting an error) so the duplicate is prevented....try this out..
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/