Script to delete records from hardware table

Navneet3
Tera Expert

Hi 

I am looking for a script to delete 5419 records from hardware table, the transform map created assets without serial numbers.

The key is SERIAL # is NULL.

find_real_file.png

 

thank you

 

1 ACCEPTED SOLUTION

Hi,

you didn't see my updated script

you had used incorrect gliderecord object which I corrected 34mins ago

sharing the script again

deleteRecords();

function deleteRecords(){
	try{
		var grAlmHardware = new GlideRecord('alm_hardware');
		grAlmHardware.addEncodedQuery("serial_numberISEMPTY");
		grAlmHardware.setLimit(5);
		grAlmHardware.query();
		gs.info(gralmHardware.getRowCount()); //check count before deleting
		while(grAlmHardware.next())
		{
			grAlmHardware.deleteRecord(); //uncomment once you verify the count got reduced by 5
		}
	}
	catch(ex){
		gs.info(ex);
	}
}

 

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

16 REPLIES 16

I am still getting the error

find_real_file.png

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use fix script for this and ensure to give correct query

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur, I got the following.

*** Script: ReferenceError: "gralmHardware" is not defined.

Hi,

you didn't see my updated script

you had used incorrect gliderecord object which I corrected 34mins ago

sharing the script again

deleteRecords();

function deleteRecords(){
	try{
		var grAlmHardware = new GlideRecord('alm_hardware');
		grAlmHardware.addEncodedQuery("serial_numberISEMPTY");
		grAlmHardware.setLimit(5);
		grAlmHardware.query();
		gs.info(gralmHardware.getRowCount()); //check count before deleting
		while(grAlmHardware.next())
		{
			grAlmHardware.deleteRecord(); //uncomment once you verify the count got reduced by 5
		}
	}
	catch(ex){
		gs.info(ex);
	}
}

 

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankita Sarkar
Tera Guru

Hi,

Try creating a Run script to delete multiple records based on the condition i.e Serial Number is NULL.

Please check this link to create a Run Script in ServiceNow: https://developer.servicenow.com/blog.do?p=/post/training-scriptsbg/

Thank You,

Ankita Sarkar