- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 06:39 AM
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?
Solved! Go to Solution.
- Labels:
-
Customer Service Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 07:45 AM
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
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 06:50 AM
Hi Julia,
Do you have the list of employee numbers or user-id for those 4710 users? If so then you can run a background script to deactivate it.
thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 06:52 AM
Hello Julia,
Use a fix script and run in background so that you can do other operation, Please find sample script. Mark my answer as correct if that helps.
var count = 0;
var gr = new GlideRecord('sys_user');
gr.addQuery("add condition here");
gr.query();
while (gr.next()) {
count++;
gr.active = false;
gr.setWorkflow(false);
gr.update();
}
gs.print("Total number of deactivated users are: " +count);
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 07:09 AM
Hey,
Most efficient way to achieve this would be background script of fix script:
var userGR = new GlideRecord('sys_user');
userGR.addEncodedQuery("add condition here");
userGR.setValue("active", false);
userGR.updateMultiple();
Refer to below article to understand how it works:
Use updateMultiple() for Maximum Efficiency!
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions š
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-02-2022 07:24 AM
For the encoded query, I'd need to put all 20,000 plus User IDs?