- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 11:02 AM
Hi All,
We get user inactivation request via catalog item , so looking for some suggestions if we can do it in bulk the inactivation of user accounts , users should automatically get removed from the groups , roles.
Any suggestions is it possible via schedule jobs.
Thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 12:47 PM
You could have a List Collector type variable so multiple users can be selected. Once submitted, set up an automation where needed to delete all sys_user_grmember and sys_user_has_role records where user.sys_idIN<list_collector_variable> kind of like below.
var userList = current.list_collector; //Get the list collector variable value here
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user.sys_id', 'IN', userList);
grMem.query();
grMem.deleteMultiple();
var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('user.sys_id', 'IN', userList);
userRole.query();
userRole.deleteMultiple();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 01:14 PM - edited 08-31-2023 01:15 PM
Hello @ServiceNow10sun ,
you can use the list_collector variable in your catalog item to get all the users that you want to deactivate, and add the following script in the workflow run script.
//To inactive Users
var grusr= new GlideRecord('sys_user');
grusr.addQuery('sys_id', 'IN',current.variables.{your variable name});
grusr.query();
grusr.active=false;
grusr.updateMultiple();
//To remove from group
var grpmbm = new GlideRecord('sys_user_grmember');
grpmbm.addQuery('user.sys_id', 'IN', current.variables.{your variable name});
grpmbm.query();
grpmbm.deleteMultiple();
//to remove roles of users
var usrl = new GlideRecord('sys_user_has_role');
usrl.addQuery('user.sys_id', 'IN', current.variables.{your varaible name});
usrl.query();
usrl.deleteMultiple();
Please mark this as the correct answer and helpful if it is resolved, or mark this helpful if this helps you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 12:47 PM
You could have a List Collector type variable so multiple users can be selected. Once submitted, set up an automation where needed to delete all sys_user_grmember and sys_user_has_role records where user.sys_idIN<list_collector_variable> kind of like below.
var userList = current.list_collector; //Get the list collector variable value here
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user.sys_id', 'IN', userList);
grMem.query();
grMem.deleteMultiple();
var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('user.sys_id', 'IN', userList);
userRole.query();
userRole.deleteMultiple();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 01:14 PM - edited 08-31-2023 01:15 PM
Hello @ServiceNow10sun ,
you can use the list_collector variable in your catalog item to get all the users that you want to deactivate, and add the following script in the workflow run script.
//To inactive Users
var grusr= new GlideRecord('sys_user');
grusr.addQuery('sys_id', 'IN',current.variables.{your variable name});
grusr.query();
grusr.active=false;
grusr.updateMultiple();
//To remove from group
var grpmbm = new GlideRecord('sys_user_grmember');
grpmbm.addQuery('user.sys_id', 'IN', current.variables.{your variable name});
grpmbm.query();
grpmbm.deleteMultiple();
//to remove roles of users
var usrl = new GlideRecord('sys_user_has_role');
usrl.addQuery('user.sys_id', 'IN', current.variables.{your varaible name});
usrl.query();
usrl.deleteMultiple();
Please mark this as the correct answer and helpful if it is resolved, or mark this helpful if this helps you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 12:09 PM
Thank you its working as expected. However i have one query as list collector is multiple selection that is array and in the above script we are not declaring any array then how its still working even when i have selected multiple users in the list collector.