- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:00 PM
I have a script like:
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('groupSTARTSWITHcatalog-^ORgroupSTARTSWITHdit-');
gr.query();
num_rows = gr.getRowCount();
gs.print('There are ' + num_rows + ' total rows to delete\n');
while(gr.next()) {
count++;
gr.deleteRecord();
}
gs.print('There were ' + count + ' rows deleted');
It runs one iteration then dies; it deletes one record, then apparently aborts. There's ~1200 records that match the query.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:15 PM
Turns out it was apparently using "gr." - when I changed that, the script ran.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:09 PM
Why don’t you use deleteMultiple
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('groupSTARTSWITHcatalog-^ORgroupSTARTSWITHdit-');
gr.deleteMultiple();
Benefits of using deleteMultiple - https://snowunderground.com/blog/2019/8/18/deleting-fast-in-servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:15 PM
Turns out it was apparently using "gr." - when I changed that, the script ran.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:17 PM
Yes, but to delete multiple record you should you deleteMultiple() as suggested by Mike. Getting into while loop will keep the script executing as many times the records is there, the best practice will be using deleteMultiple() function and delete the multiple records at once without any loop.