Inactive user Records

rabbanis
Tera Contributor

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?

2 ACCEPTED SOLUTIONS

Community Alums
Not applicable

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::.

View solution in original post

Community Alums
Not applicable

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::.

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

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::.

But what about re-assigned to assignment group member and adding work note part?

Community Alums
Not applicable

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::.