deletemultiple() takes too long
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2020 12:05 PM
I am using deleteMultiple() command in a fix script to delete unwanted records.
I have nearly 200 K records in Group Member table which I don't need.
I created a fix script. The Fix Script takes forever to complete.
On an average it is deleting 1000 records in 5 minutes. Is this expected or am I doing something wrong?
Here is my Script:
var grpMembers = new GlideRecord('sys_user_grmember');
grpMembers.addQuery('user.name', grUsersEmptyGroups.getValue('u_username'));
grpMembers.addQuery('group.name', '');
grpMembers.setWorkflow(false);
grpMembers.deleteMultiple();
----
grUsersEmptyGroups.getValue('u_username') I am passing from an outer query which is basically a user name.
Let me know how to improve my query and delete records quicker.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2020 12:33 PM
Hi,
As others already mentioned deleteMultiple do take time.
I would rather put a setLimit(50) and then put it inside a while loop and run it in a scheduled job. This way, the transactions will be faster and will not take lot of system resources.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2020 06:05 AM
Yeah as everyone who replied pointed out, scheduled job with setlimit yielded better results. Just to automate the process, we created a custom table which keeps track of processed and non processed users. Daily the job will pick up 25 yet to be processed user names and execute delete multiple on those limited set.
We are guessing the scheduled job might take a week to complete based on our data and off peak times that we chose to run.
Thanks everyone for your inputs.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2020 07:26 AM
Great to know you implemented it. Kindly mark the thread as correct & close it so that it does not appear in unanswered list.