- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2022 08:00 PM
Hi, Totally newbie here. I would like to ask how to prevent creation of a new record, if a record already existed in business rule.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2022 08:50 PM
Hi,
why not make the u_reference_1 field as Unique at dictionary level?
In this way no business rule is required
In case you still want to use business rule then use this
Before Insert
Script:
var gr = new GlideRecord(current.getTableName());
gr.addQuery("u_reference_1", current.u_reference_1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage("not allowed");
current.setAbortAction(true);
}
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
‎03-21-2022 08:50 PM
Hi,
why not make the u_reference_1 field as Unique at dictionary level?
In this way no business rule is required
In case you still want to use business rule then use this
Before Insert
Script:
var gr = new GlideRecord(current.getTableName());
gr.addQuery("u_reference_1", current.u_reference_1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage("not allowed");
current.setAbortAction(true);
}
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
‎03-21-2022 09:30 PM
thank you man. How Brilliant!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2022 09:36 PM
Glad to know that it helped.
Please mark response helpful as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader