Unable to Delete Assets and Computers via Fix Script

syed_but_not
Tera Expert

HI, I'm attempting to delete all of our CI's that were brought in via our SCCM integration, I've tried the following code but it does not delete all the records. 

var ci = new GlideRecord('cmdb_ci');
ci.addEncodedQuery('discovery_source=SG-SCCM^sys_class_name=cmdb_ci_computer');
ci.query();
while(ci.next()){
	ci.deleteMultiple();
}

var computer = new GlideRecord('cmdb_ci_computer');
computer.addEncodedQuery('discovery_source=SG-SCCM');
computer.query();
while(computer.next()){
	computer.deleteMultiple();
}
var hardware = new GlideRecord('alm_hardware');
hardware.addEncodedQuery('ci.discovery_source=SG-SCCM');
hardware.query();
while(hardware.next()){
	hardware.deleteMultiple();
}

 

6 REPLIES 6

Community Alums
Not applicable

Hello @AshishKM ,

// delete all record from alm_hardware table

var hardware = new GlideRecord('alm_hardware'); hardware.addEncodedQuery('ci.discovery_source=SG-SCCM');

hardware.query();

hardware.deleteMultiple();

 

We used above script to delete data but it only deletes 100 records at a time and stops execution.

 

SK Chand Basha
Giga Sage

Hi @syed_but_not without scripting we can use Delete jobs.

 

I'm sharing the link below with an example.

 

Update or Delete Bulk Records without Scripting - ServiceNow Community

 

Mark this Helpful !!. If this Helps you to understand. This will help both the community and me.