Background Script to update the request state

kavya40
Kilo Contributor

Hi ,

 

I am trying to close the requests associated with request Item but it is not successfull , below is my code , Kindly help with it

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('state=3^ORstate=4^request.request_stateINrequested,in_process');
gr.query();
while(gr.next()) {

 

gr.setValue('request.request_state',closed_complete); //    request_state should be updated with  Label: Closed Complete value : closed_complete
gr.autoSysFields(false);
gr.update();

 

}

1 REPLY 1

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Try below code 

var gr = new GlideRecord('sc_req_item');

gr.addEncodedQuery('state=3^ORstate=4^request.request_stateINrequested,in_process');

gr.query();

while(gr.next()) {

var req=new GlideRecord('sc_request');

req.addQuery('sys_id',gr.request); //confirm field name from RITM table

req.query();

if(req.next()){

req.request_state='closed_complete'; //    request_state should be updated with  Label: Closed Complete value : closed_complete

req.autoSysFields(false);

req.update();

}

 

 

 

}

 

 


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