- 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:14 AM
Here you go
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.setWorkflow(false);
gs.print("the count is "+psc.getRowCount());
psc.deleteMutiple();

- 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:22 AM
A minor correction. Should have been addEncodedQuery() instead of addQuery()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2016 10:33 AM
That should work though