- 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 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 08:46 AM
var userGR = new GlideRecord('sys_user');
userGR.addEncodedQuery("add condition here");
userGR.setValue("active", false);
userGR.setWorkflow(false);
userGR.updateMultiple();
Regards,
Musab

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