- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 02:44 AM
I'm trying to bulk delete 'Inactive' users from the sys_user table using a background script after a clone, but it's taking a long time to delete even 10 users records. After a while, the system becomes unresponsive.
var gr = new GlideRecord('sys_user');
gr.addQuery('active', false);
gr.query();
var count = 0;
while (gr.next() && count < 10) {
gr.deleteRecord();
count++;
}
gs.print('Deleted ' + count + ' inactive users.');
Is there any better way to doing the above script ?
I tried multiple record deletion as well, but same result.
var gr = new GlideRecord(sys_user);
gr.addQuery('active', false);
gr.setLimit(10); //limit only first 2 record
gr.query();
gr.deleteMultiple();
I noticed there's a 'Clone Cleanup Script', but I've never used it before and I'm not sure how to test it either.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 03:10 AM
Hi @attanhes
May I ask why you want to delete the records? It's generally not a best practice to remove foundation records. However, if you prefer not to see inactive users in sys_user table, you can set up an archive rule to move them to the archived table. I assume this is being done in non-production environments.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 03:10 AM
Hi @attanhes
May I ask why you want to delete the records? It's generally not a best practice to remove foundation records. However, if you prefer not to see inactive users in sys_user table, you can set up an archive rule to move them to the archived table. I assume this is being done in non-production environments.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 04:30 AM
Thanks, everyone. My goal is to clone configuration only to the sandbox environment for a project. I was able to successfully separate the data and clone configuration-only for all modules, except for the sys_user table.
When I excluded the sys_user table and its associated tables as advice by Service Now, certain functionalities broken even though XML import into sandbox.
So now I'm working on Plan B — cloning all users and then deleting the unwanted users in the sandbox environment which is not ideal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 05:03 AM - edited ‎06-05-2025 05:04 AM
@attanhes ok got it..
Try to run the same in fix script (run background).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 04:08 PM - edited ‎06-06-2025 04:09 PM
Thanks, J — your tip was very helpful. I archived the unwanted users in the non-prod environments and then cloned the target while excluding the archived(ar_sys_user)table. Problem solved!
No needed to run background script after cloning to delete the accounts as unwanted user accounts already left in source in that way. I would never recommend doing this in a production environment as mentioned in J's post. Fortunately, I was working with two non-prod instances for this exercise.