Close out old Requests using a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 07:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 07:24 AM
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 07:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 08:03 AM
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:
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 09:15 AM
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
}
}