- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 07:07 AM
can you please make sure there are no active/open tasks (not in the strict record-type sense, but incidents, approvals, requests, changes, ...) assigned to deactivated user accounts?
1. If there are still active tickets/records assigned to these users, these will have to be picked up by the other members of the group the ticket is assigned to. So for those tickets: please add a worknote (not visible to end users!)
"removed [deactivated user's name] from the 'assigned to' field as this user account is no longer active in ServiceNow"
2. If there are still active tickets for which a deactivated user is the affected user, it depends on the user/ticket content what needs to be done. So please provide me with a url to a list with those tickets, grouped by (deactivated) user and (2nd layer) grouped by assignment group.
3. After that, please remove all roles from the deactivated users and remove them from all groups they are a member of
This is my requirement
could you please suggest any one how to achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 07:59 AM
Hi,
Please check the below code to clear assigned to field if user is inactive:
var user = current.getValue("sys_id"); //should usually use a string version of the data
var inc = new GlideRecord("incident");
//added extra filter so closed/cancelled records are not re-assigned
inc.addEncodedQuery("active=true^assigned_to=" + user);
inc.query();
while(inc.next()){
inc.assigned_to = "";
inc.work_notes='Assiged to changed to empty as user is inactive';
inc.update();
}
})(current, previous);
And to remove roles and from groups:
---->var gr = new GlideRecord('sys_user_has_role');
gr.addEncodedQuery('user.locked_out=true^user.active=false');
gr.query();
while(gr.next()){
gr.deleteRecord();
}
-->var grUser = new GlideRecord('sys_user_grmember');
grUser.addEncodedQuery('user.active=false');
gr.query();
while(grUser.next()){
grUser.deleteMultiple();
}
Please mark the answer correct/helpful accordingly::.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 08:16 AM
Hi,
We can get the incidents list with assigned to field is empty so they can be assigned to anyone within the group. And we can know the reason why assigned to field is empty in that incident through work notes.
Please mark the answer correct/helpful accordingly::.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 07:59 AM
Hi,
Please check the below code to clear assigned to field if user is inactive:
var user = current.getValue("sys_id"); //should usually use a string version of the data
var inc = new GlideRecord("incident");
//added extra filter so closed/cancelled records are not re-assigned
inc.addEncodedQuery("active=true^assigned_to=" + user);
inc.query();
while(inc.next()){
inc.assigned_to = "";
inc.work_notes='Assiged to changed to empty as user is inactive';
inc.update();
}
})(current, previous);
And to remove roles and from groups:
---->var gr = new GlideRecord('sys_user_has_role');
gr.addEncodedQuery('user.locked_out=true^user.active=false');
gr.query();
while(gr.next()){
gr.deleteRecord();
}
-->var grUser = new GlideRecord('sys_user_grmember');
grUser.addEncodedQuery('user.active=false');
gr.query();
while(grUser.next()){
grUser.deleteMultiple();
}
Please mark the answer correct/helpful accordingly::.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 08:04 AM
But what about re-assigned to assignment group member and adding work note part?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 08:16 AM
Hi,
We can get the incidents list with assigned to field is empty so they can be assigned to anyone within the group. And we can know the reason why assigned to field is empty in that incident through work notes.
Please mark the answer correct/helpful accordingly::.