Reassign Open tickets to group and remove member from group when user is marked inactive

Atheher Fathima
Mega Guru

Hi All,

 

i have a requirement that whenever a user is marked inactive in sys_user table,

1. we need to check open incidents, tasks, problems and assign them to the group itself(make assigned to blank)

2.For any applications/CI where user is a owner/tech lead - generate a list and trigger notification

3.Remove the user from the group

 

I tried to create a scheduled job to remove members from group and created a BR on sys_user_grmember to reassign the open tasks to group.however i see that it is also removing assigned to for Resolved tickets as well and unable to achieve point 2.

below is my script 

(function executeRule(current, previous /*null when async*/) {
    var groupId = current.getValue("group");
    var groupName = current.group.getDisplayValue();
    var userId = current.getValue("user");
    var userName = current.user.getDisplayValue();

    //look for all Active Task records assigned to the Group AND User
    var grpm = new GlideRecord("task");
    grpm.addEncodedQuery("active=true^assignment_group=" + groupId + "^assigned_to=" + userId);
    grpm.query();
    while (grpm.next()) {
        //add a work note to let people know why the field was cleared
        grpm.work_notes.setJournalEntry("Assigned to field cleared because '" + userName + "' was removed from the current Assignment group '" + groupName + "'");
        grpm.assigned_to = "";
        grpm.update();
    }
})(current, previous);

 

Can someone please help on how i can achieve this with a BR on sys_user table itself on when active changes to false? any help on this will be greatly appreciated

1 ACCEPTED SOLUTION

Martin Ivanov
Giga Sage
Giga Sage

Please mark Correct and Helpful if my answer helps you resolve your issue.

Тhis will close the thread and other users may also benefit from it.

Thanks!
Martin Ivanov
Community Rising Star 2022


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

View solution in original post

10 REPLIES 10

atul_05
Tera Contributor

Hi @Atheher Fathima 
Can you please share the flow that you have created to achieve this requirement. It will be really helpful.