Business Rule does not abort State advancement
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The Filter Conditions covers when you want the script to run, so you don't need this script wrapped in an if statement that might not ever be true(is the value the number 3 or the string '3'???)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @lbless1 !!
The issue is that choice fields like state store numeric backend values, not labels. Your BR is comparing current.state to a string ('Screening'), so it never triggers.
Fix: Compare against the numeric value of the choice:
if (current.state == 3 && previous.state != 3) {
current.setAbortAction(true);
gs.addErrorMessage('At least one attachment is required before moving to Screening.');
}This ensures the BR correctly blocks the state change when no attachment exists.
Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.
Regards,
Vaishnavi
Technical Consultant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @lbless1 ,
Your overall business rule seems to be fine but in your if condition you are checking state , please ensure that whether you state is string or numeric (integer). If its integer type then might is not getting evaluated true and other code is not working .
If this helps you then mark it as helpful and accept as solution.
regards,
Aditya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @lbless1
While your script works, hardcoding the table name ('dmn_demand') can cause issues if you ever extend the table or copy the script. It is safer to use current.getTableName()
(function executeRule(current, previous) {
// Only enforce when moving to Screening (State 3)
// AND ensure the state has actually changed
if (current.state == '3' && previous.state != '3') {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', current.sys_id);
// Dynamically get the table name to make the script robust
att.addQuery('table_name', current.getTableName());
att.setLimit(1); // Performance optimization
att.query();
if (!att.hasNext()) {
gs.addErrorMessage('At least one attachment is required before moving to Screening.');
current.setAbortAction(true);
// Optional: Reset the state back to previous to reflect in UI immediately
// current.state = previous.state;
}
}
})(current, previous);
Happy to help!
To help others in the community find this solution, kindly mark this response as the Correct Answer and Helpful.
Warm Regards,
Deepak Sharma
Community Rising Star 2025

