Deactivate large set of users

Julia Howells
Giga Guru

I have a list of active users from Workday. The count of total employees is inaccurate in ServiceNow. I need to find any employees that are not on my active list and deactivate them in ServiceNow.

One caveat is that I need this to NOT deactivate any Contacts that are not on my list as well. We have 1,897 contacts and 20,551 active employees. 

ServiceNow active user count is 27,158.

With contacts and active employees, our count should be 22,448 (ish) so we have just about 4,710 users that need to be deactivated. Is there a clean way to run this?

1 ACCEPTED SOLUTION

You can use condition for the users, lets say hypothetically you come to decide, all users which are active and first name is Dwight, condition would be

addEncodedQuery("active=true^first_name=Dwight");

 

Or by scripting you can fetch the list of sys_ids in an array and set in encoded query,

addEncodedQuery("sys_idIN"+userArray);// assuming userArray has list of sys_ids you want to deactivate

Best Regards
Aman Kumar

View solution in original post

7 REPLIES 7

You can use condition for the users, lets say hypothetically you come to decide, all users which are active and first name is Dwight, condition would be

addEncodedQuery("active=true^first_name=Dwight");

 

Or by scripting you can fetch the list of sys_ids in an array and set in encoded query,

addEncodedQuery("sys_idIN"+userArray);// assuming userArray has list of sys_ids you want to deactivate

Best Regards
Aman Kumar

@Aman Kumar @Julia Howells Don't forgot to add setWorkflow(false) to your code whenever running something in background script, this will disable other code running on table, I'm not 100% sure how it will be behave with updateMultiple() though but try in lower instance

var userGR = new GlideRecord('sys_user');
userGR.addEncodedQuery("add condition here");
userGR.setValue("active", false);
userGR.setWorkflow(false);
userGR.updateMultiple();
Please hit like and mark my response as correct if that helps
Regards,
Musab

Hey Musab,

I agree with using setWorkflow() and also autoSysFields for that matter, with bg script, but I think there will be cases where you want the engines to also run the backend engine to adjust with normal system behavior.

Best Regards
Aman Kumar