- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2020 04:53 AM
We have a clone scheduled in near future. So when we clone prod instance to QA. The requests will also be migrated. So we need to delete few requests related to particular catalog items. Please help me with the script to delete the requests after clone.
Solved! Go to Solution.
- Labels:
-
Finance Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2020 05:10 AM
You can use Post-clone cleanup scripts and do your scripting
Cleanup scripts automatically run on the target instance after the cloning process finishes.
Sample script below
You might have to delete sc_task records for that RITM as well
deleteRecords();
function deleteRecords(){
try{
var itemName = 'Apple iPhone5';
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item.name', itemName);
ritm.query();
while(ritm.next()){
// find and delete REQ
var req = new GlideRecord('sc_request');
req.get(ritm.request);
req.deleteRecord();
// find and delete sc_task
var scTask = new GlideRecord('sc_task');
scTask.addQuery('request_item', ritm.sys_id);
scTask.query();
scTask.deleteMultiple();
// then delete RITM
ritm.deleteRecord();
}
}
catch(ex){
gs.info('Exception'+ex);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2021 11:18 PM