- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2023 02:34 PM
Hi,
I have a requirement that any RITM state cannot be changed to Closed Complete manually if there are pending Approvals for the RITM.
I have created a Before Business Rule on the sc_req_item table and used the following script, however it is still allowing me to close a RITM. PLease advise what am I missing.
(function executeRule(current, previous /*null when async*/ ) {
//Checks for any Active approval and aborts the update if active
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', current.sys_id);
gr.addQuery('state', 'requested');
gr.query();
if (gr.hasNext()) {
gs.addInfoMessage("There are open approvals which must be completed before this record can be closed");
current.setAbortAction(true);
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2023 08:54 PM
Did you add gs.info() to check if BR ran?
whether query is working fine?
try this
(function executeRule(current, previous /*null when async*/ ) {
//Checks for any Active approval and aborts the update if active
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', current.sys_id).addOrCondition('sysapproval', current.sys_id);
gr.addQuery('state', 'requested');
gr.query();
if (gr.hasNext()) {
gs.addInfoMessage("There are open approvals which must be completed before this record can be closed");
current.setAbortAction(true);
}
})(current, previous);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2023 01:11 PM
Hi,
I'm glad you found an answer that worked for you.
I'd still recommend reviewing my reply as similar suggestions were stated.
I hope at a minimum, it was helpful. Keep in mind that if multiple solutions assisted you, you can accept more than one solution as well 🙂
Take care!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2023 08:54 PM
Did you add gs.info() to check if BR ran?
whether query is working fine?
try this
(function executeRule(current, previous /*null when async*/ ) {
//Checks for any Active approval and aborts the update if active
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', current.sys_id).addOrCondition('sysapproval', current.sys_id);
gr.addQuery('state', 'requested');
gr.query();
if (gr.hasNext()) {
gs.addInfoMessage("There are open approvals which must be completed before this record can be closed");
current.setAbortAction(true);
}
})(current, previous);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2024 11:06 AM
when i try this, my record still updates, it does not abort. I do receive the message, but it will still update the record. suggestions?