code not working, wanted to check if the ritm is approved or not

BrightJunin
Tera Contributor

hi All, 

i have more then 3000 request records, where i have to checked if the RITM is approved or not.

but my below code is not giving me any output.

Can you please edit my code and help me 

 

CODE:-

var n;
var v = new GlideRecord('sc_req_item');
v.addEncodedQuery('numberINRITM8513815,RITM8513711');
v.query();
while (v.next()) {
n = v.number;

}
var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('sysapproval.name', n);
ap.addQuery();

while (ap.next()) {

gs.log(ap.state);
}

4 REPLIES 4

James Chun
Kilo Patron

Hi @BrightJunin,

 

If you are checking if the RITMs are approved or not, there is no need to query the [sysapproval_approver] records.

You can simply check the 'approval' field of the RITM.

e.g. v.getValue('approval') == 'approved'

 

Cheers

hi James, 

 

i want to see the state of all the approvals from sysapproval_approver for given RITMs

 

Now there can be group approvals & manager approval .... 

You can try the following:

 

var ap = new GlideRecord('sysapproval_approver');
ap.addEncodedQuery('sysapproval.numberINRITM8513815,RITM8513711');
ap.query();
while (ap.next()) {
    gs.log(ap.state);
}

 

Ankur Bawiskar
Tera Patron
Tera Patron

@BrightJunin 

I agree with @James Chun 

Please use approval field available OOTB on RITM table to determine if RITM was approved or not

If my response helped please mark it correct and close the thread so that it benefits future readers.

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