Business Rule does not abort State advancement
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have a BR to require an attachment, however it is not preventing the State from progressing.
(function executeRule(current, previous) {
// Only enforce when moving to Screening
if (current.state == '3' && previous.state != '3') {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', current.sys_id);
att.addQuery('table_name', 'dmn_demand');
att.setLimit(1);
att.query();
if (!att.hasNext()) {
gs.addErrorMessage('At least one attachment is required before moving to Screening.');
current.setAbortAction(true);
}
}
})(current, previous);
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you are already checking state value in BR filter condition, so no need of that in script to check
(function executeRule(current, previous) {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', current.sys_id);
att.setLimit(1);
att.query();
if (!att.hasNext()) {
gs.addErrorMessage('At least one attachment is required before moving to Screening.');
current.setAbortAction(true);
}
})(current, previous);
OR
You can use this small script and no need to query sys_attachment table
(function executeRule(current, previous) {
if (!current.hasAttachments()) {
gs.addErrorMessage('At least one attachment is required before moving to Screening.');
current.setAbortAction(true);
}
})(current, previous);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Regards,
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi
Please correct your if condition-
(function executeRule(current, previous) {
// Only enforce when moving to Screening
if (current.state == 3 && previous.state != 3) {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', current.sys_id);
att.addQuery('table_name', 'dmn_demand');
att.setLimit(1 );
att.query();
if (!att.hasNext()) {
gs.addErrorMessage('At least one attachment is required before moving to Screening.');
current.setAbortAction(true);
}
}
})(current, previous);
Hope , it will work!

