Unable to delete record from Sys_object_source table
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 05:42 AM - edited 05-30-2025 05:47 AM
Hi all,
I have a requirement to delete all the records in sys_object_source table where reference CIs are in Retired status.
I am facing an issue while running below script in background
Issue- The below script does query the source record based on the sys_id found in CMDB. When you provide
hard coded value like var retiredCIs = new GlideRecord('cmdb_ci');
retiredCIs.addEncodedQuery('sys_id=0199290f1bc470901b76cb392a4bcbb6'); then it works fine but I need to delete millions of records, so I was using below script which is not working. Can someone help me. geeting sourceRecords is undifined
Script:
// Get all retired CIs
var retiredCIs = new GlideRecord('cmdb_ci');
retiredCIs.addQuery('install_status', '7');
retiredCIs.setLimit('10');
retiredCIs.query();
while(retiredCIs.next()) {
var ciSysId = retiredCIs.getUniqueValue();
// Get corresponding records from "sys_object_source" so that we can delete them.
var sourceRecords = new GlideRecord('sys_object_source');
sourceRecords.addQuery('target_sys_id', ciSysId);
sourceRecords.setWorkflow(false);
//sourceRecords.setLimit(10);
sourceRecords.query();
while(sourceRecords.next()) {
gs.info("IAMIN Source record "+ sourceRecords.name + " Target CI "+ retiredCIs.sys_id);
sourceRecords.deleteMultiple();
}
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 05:49 AM
did you try deleting 100 records first?
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader