- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 10:12 AM
Hi Everyone,
I am trying to delete around 8k records in our instance. Below script is not working. Do we really require while loop in order for the below script to work properly?
var qry = 'short_description=Warning: could not send message for past 4 hours';
var psc = new GlideRecord('hr');
psc.addEncodedQuery(qry);
psc.setLimit('10');
psc.query();
gs.print("the count is "+psc.getRowCount());
psc.deleteMutiple();
Thanks,
Rahul kathuria
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 10:21 AM
Hi Rahul,
Here is the modified business rule along with comment. Make sure table name is correct
updateHrRecords();
function updateHrRecords()
{
var psc = new GlideRecord('hr'); //Make sure table name is correct
psc.addQuery('short_description=Warning: could not send message for past 4 hours');
psc.setLimit('10');
psc.setWorkflow(false); //Turn off business rule or notifications
gs.print("the count is "+psc.getRowCount());
psc.deleteMultiple();
}
References:
Remove All Data from a Table - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 10:31 AM
Hi Pradeep/Abhinay,
This is simply not working. Although i am able to delete records using below code but the processing is very slow, i mean in 140 sec it deleted only 7 records. so i am trying to search for an alternative which can do this processing without any loop or delay.
var qry = 'short_description=Warning: could not send message for past 4 hours';
var psc = new GlideRecord('hr');
psc.addEncodedQuery(qry);
psc.query();
gs.print("the count is "+psc.getRowCount());
//gs.deleteMutiple();
while(psc.next()){
psc.deleteMultiple();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 10:34 AM
Did you try using the modified query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 10:37 AM
i ran your script in background scripts,
- var psc = new GlideRecord('hr'); //Make sure table name is correct
- psc.addQuery('short_description=Warning: could not send message for past 4 hours');
- psc.setLimit('10');
- psc.setWorkflow(false); //Turn off business rule or notifications
- gs.print("the count is "+psc.getRowCount());
- psc.deleteMutiple();
and this is the output:
[0:00:00.004] Script completed: script
*** Script: the count is 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 11:02 AM
This is working now. there was a spelling mistake. i was using mutiple instead of multiple.
psc.deleteMutiple();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 11:49 AM
Glad you figured it out
Please mark response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list. Thank you