You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This snippet assigns specific roles to users based on their department within ServiceNow.
1
+
# Overview
2
+
This snippet for ServiceNow developers automate the process of assigning roles to users based on their department. It helps to simplify user role management, especially useful in organizations where specific departments require predefined access levels.
2
3
3
-
Departments are matched against a predefined dictionary, and roles are applied accordingly. To modify, update the `rolesByDepartment` dictionary with your organization’s department-role mappings.
4
+
5
+
# How It Works
6
+
The script:
7
+
-**Identifies the User's Department**: Retrieves the department name of the current user, which is then used as a key to look up relevant roles.
8
+
-**Defines Role Mappings**: Uses a dictionary `rolesByDepartment` to map departments (like IT, HR, and Finance) to arrays of role names.
9
+
-**Assigns or Removes Roles**:
10
+
- Clears Existing Roles: Empties the user’s current role list to avoid duplicate or outdated assignments.
11
+
- Adds New Roles: Based on the department lookup, the script assigns the appropriate roles from the predefined list.
12
+
13
+
# Implementation
14
+
15
+
Update `rolesByDepartment` to reflect your organization’s specific department-role mappings.
4
16
```
5
17
var rolesByDepartment = {
6
18
<department_name> : [role_1, role_2]
7
19
};
8
-
```
9
-
10
-
11
-
This script ensures automatic and consistent role assignment, streamlining access control for large teams.
0 commit comments