Skip to content

Auto role assignment by department #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

wendy-ha18
Copy link
Contributor

Overview

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.

This script has been moved to under folder Business Rule based on @Lacah comment on this closed PR: #1549.

Current repo structure:

  • Business Rules/Automate Role Assignment for New User/README.md
  • Business Rules/Automate Role Assignment for New User/autoRoleAssignment.js

How It Works

In Business Rule settings within ServiceNow:

  • Trigger: runs the script "before" an update to the sys_user table when a user’s department changes.
  • Condition: Only triggers when current.department.changes() - ensures that the script only runs when the department field is modified.
  • Role Mapping: Uses the rolesByDepartment dictionary to assign roles based on the user’s department.

Implementation

Edit rolesByDepartment to match your organization’s needs.

var rolesByDepartment = {
        <department_name> : [role_1, role_2]
    };

@Lacah Lacah self-assigned this Oct 29, 2024
@Lacah Lacah merged commit cf4887a into ServiceNowDevProgram:main Oct 29, 2024
1 check passed
@wendy-ha18 wendy-ha18 deleted the feature/auto-role-assignment-by-department branch October 29, 2024 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants