- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2015 09:32 AM
Greetings All,
I have written a script to delete those users whose Email, User ID, Ldap-Server is blank. Please let me know if it is ok.
var encodedQuery="emailISEMPTY^user_nameISEMPTY^ldap_serverISEMPTY"; // semicolon added
var gr = new GlideRecord("sys_user"); //error here " needed to be closed
gr.addEncodedQuery(encodedQuery);
gr.deleteMultiple();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2015 10:29 AM
If you do go with deactivating, rather than deleting, I'd do it through the UI:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2015 10:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2015 02:34 PM
Cascade Delete Rules are also an option if you are wanting to make sure records will not get orphaned. This may take time to set up, so probably only beneficial if you are aware of the specific tables that would possibly be affected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2015 02:38 AM
Hi rfedoruk,
i don't know how to check this. If you can guide then it will be helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2015 07:26 AM
Won't be able to generate the script for you at the moment, but you'd need to cross reference the list of sys_id's you want to delete with any user reference field in any other table. If you've got any positives you need to either adjust the data before hand.
For example:
- how many tasks have these rogue user accounts had created in their name? Will your customer be satisfied with "null" showing up as they group task history by data determined by user (cost code, department, company, manager, etc)
- how many tasks have these rogue user accounts had assigned to them?
- what group memberships are these rogue user accounts associated with?
- how many reports are targeted to them?
- how many scheduled jobs send report output to them?
- how many notifications are they hard coded into?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2015 10:35 AM
But, yes, if you are sure you want to delete every user that has none of these attributes set, that is the way to do it. Some things that might help you when doing inserts, updates, and deletions are:
setLimit(10); // allows you to perform your action on a sample size before the big delete (in this case, 10
autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on
setWorkflow(false); // Do not run any other business rules