Close out old Requests using a script

Mallika Bhupath
Tera Contributor

All,

 

I opened a HI ServiceNow ticket to close out some older requests that do not have any RITM or SCTASKs. This happened as we were setting up ServiceNow and did not have proper workflows configured. 

 

Since, they are over 5 years old, the engineer said they would not have any logs and there is no best practice or KB article to close out such a request. Instead, he suggested me to update the state of the request to Close Complete by using a script.

 

Can someone please help me with it? I have attached a few screenshots of the requests as well. 

 

Thanks,

Mallika

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Mallika Bhupath 

I guess that is right answer, Better you run the script and update the status. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG ,

 

Can you please help me with the script?

 

Thanks,

Mallika

Hi @Mallika Bhupath 

 

I am not a great coder who can provide you script but can give you a path:

- You can create a mapping table 

- Like we have for CMDB - Asset.

- Build BR to synch.

 

Example:

https://INSTANCENAME.service-now.com/now/nav/ui/classic/params/target/alm_asset_ci_field_mapping_lis...

 

There are two OOTB Business Rules : "Update Asset fields on change" and "Update CI fields on change" which use   "AssetAndCISynchronizer" class to synchronize Assets and CIs.

 

Check these code . hope this will helpful. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

jonsan09
Giga Sage
Giga Sage

This is not complete but this would a start for a background script or scheduled job. You'll want to make sure to test this out with a few records in a PDI or non-Prodcution enviorment first. 

 

var eReq = new GlideRecord('sc_request');
eReq.addEncodedQuery('active=true'); //This might need to be changed to match your requests
eReq.setLimit(1); //Use to limit for testing or to limit for batching to prevent performance issues
eReq.query();
while (eReq.next()) {

    var reqChk = new GlideRecord('sc_req_item');
    reqChk.addEncodedQuery('request=' + eReq);
    reqChk.setLimit(1);
    reqChk.query();
    if (reqChk.next()) {
        gs.log('This record exists: ' + eReq.number);
        
    } else {
        gs.log('Does not exist');
	//Add code to update the eReq record to closed
    }

}