We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Abort RITM Closure if Pending Approvals are present

Arijit Saikia
Tera Contributor

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);

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@Arijit Saikia 

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);

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

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!

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron

@Arijit Saikia 

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);

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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?