- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 06:31 AM
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.
thank you
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 08:33 AM
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);
}
}
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
03-08-2022 07:21 AM
You can run it as background script or as a fix script as ankur mentioned.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 07:25 AM
Ankur, The table is alm_hardware not cmdb table
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 07:29 AM
please enhance the script from your side.
It was just an example
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 07:53 AM
is this right?
deleteRecords();
function deleteRecords(){
try{
var grAlmHardware = new GlideRecord('alm_hardware');
grAlmHardware.addEncodedQuery("serial_numberISEMPTY");
gralmHardware.query();
gs.print(gralmHardware.getRowCount()); //check count before deleting
while(grAlmHardware.next())
{
//grCmdbCiHardware.deleteRecord(); //uncomment for delet
}
}
catch(ex){
gs.info(ex);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 07:59 AM
yes
Minor changes
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);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader