Thursday, September 27, 2018

ServiceNow script to remove inactive user from all the groups and roles

function removeTheGroupsOfInactiveUser() {
        var groupGR = new GlideRecord('sys_user_grmember');
        groupGR.addQuery('user', current.u_employee_name);
        groupGR.query();
        while (groupGR.next()) {
                groupGR.deleteRecord();
        }
}


function removeTheRolesOfInactiveUser() {
        var roleGR = new GlideRecord('sys_user_has_role');
        roleGR.addQuery('user', current.u_employee_name);
        roleGR.query();
        while (roleGR.next()) {
                roleGR.deleteRecord();
        }
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.