Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to check approval state for change request

anilkumarsharma
Giga Guru

@Ankur Bawiskar 

@Gunjan Kiratkar

Good morning All,

 i want to check that state of the approval are approved not against change number CHG0000087 if all are not approved the send notification.

 

Please let me know How will I check? Please help.

 i used hasnext() in while loop to check the record but background script went in infinite loop.

 

anilkumarsharma_0-1674624085609.png

 

var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('sysapproval.number=CHG0000087^state=approved');
gr.query()
gs.info("Print number:"+gr.getRowCount());
while(gr.next()){

gs.info("print state:"+gr.state);
}
1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @anilkumarsharma 

You can do something like below:-

var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('sysapproval=e2cdf552db252200a6a2b31be0b8f57f^state!=not_required^ORstate=NULL'); //Copy encoded query from list view
gr.query()
var allCount=gr.getRowCount();
var approvedCount=0;
while(gr.next() && gr.state=='approved'){
approvedCount++;
}
if(approvedCount==allCount){

gs.eventQueue("EventName");

}

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

5 REPLIES 5

Thanks, Sir, for update.