- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 02:08 AM
Hi all,
I recently included a field into our LDAP import, this has forced 42,000 records to be imported to the Sys_User table.
I need to remove these, i don't mind deleting all users and running a new import (this would be the better option).
Does anyone know how to do this?
Thanks,
Andrew
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 02:45 AM
Slight modifications
Firstly id recommmend you do this in batches, lets say 10k at a time
function removeComputers() {
var gr = new GlideRecord("sys_user");
gr.addEncodedQuery('user_name=null');
gs.setLimit(10000);
gr.setWorkflow(false);
gr.query();
var deleteCount = 0;
while(gr.next()){
gr.deleteRecord();
deleteCount++;
}
gs.print('Records Deleted: '+ deleteCount);
}
Also noticed something odd at the start of your script, make sure its not a copy paste error, you are calling a different function and the deletion function has s different name.
deleteSys_user();
function removeComputers() {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 02:20 AM
Hi Andrew,
you can write a background script or scheduled job which would run ondemand
you need to ensure proper query is applied before deleting the users
also during query use setLimit(10) to check for 10 records and then comment it out
var gr = new GlideRecord('sys_user');
gr.addNullQuery('user_name');
gr.setLimit(10);
gr.query();
gr.deleteMultiple();
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 02:26 AM
Ankush,
You are missing gr.query();
Thanks. Prashant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 02:48 AM
Hi,
Thanks for the correction, updated the same.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2019 02:20 AM
Hello Andrew,
Check out this:
var gr = new GlideRecord('sys_user');
gr.addNullQuery('user_name'); // return all user id having null value
//gr.setLimit(1000);
gr.query();
gr.deleteMultiple();
Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade