What This Table Is
The sys_user_role table stores security role definitions that form the backbone of ServiceNow's access control system. Each record represents a distinct role like 'incident_manager', 'admin', or 'itil', defining what features users can access and what data they can see. These roles work in conjunction with ACL rules, UI policies, and application menu restrictions to enforce security boundaries.
Owned by the Platform module, this table supports the entire role-based access control (RBAC) process from user provisioning to real-time permission checks. When a user logs in, ServiceNow builds their effective role list by querying this table through the sys_user_has_role many-to-many relationship. Every authorization check — whether it's loading a form, executing a script, or showing a UI action — ultimately traces back to the roles defined here.
This table doesn't extend another table and isn't commonly extended. However, it participates in a complex hierarchy system through the contains_roles field, allowing roles to inherit permissions from other roles. The elevated_privilege field marks high-security roles that require additional authentication for certain operations.
In large enterprises, expect 200-800 role records depending on customization depth. Performance is generally excellent since this table is heavily cached and indexed. Role evaluation happens at session start and is cached in memory, so frequent role changes can cause cache invalidation across the cluster. High-volume role modifications during business hours should be avoided.
When You'll Script Against This Table
You'll query sys_user_role in Business Rules when implementing custom authorization logic, Script Includes when building role utilities, and UI Scripts when showing/hiding interface elements based on role membership. Client-side access is limited by ACLs — you can typically read role names but not modify role assignments. Background scripts and scheduled jobs frequently query this table for bulk user provisioning and compliance reporting.
Access requires the user_admin role for write operations and typically admin for structural changes like modifying role hierarchies. Standard users can query their own role information through gs.hasRole() but cannot directly access the table records.
Common scripting patterns:
- Building custom role assignment logic in User Management flows
- Creating role-based approval routing in workflow activities
- Generating compliance reports showing role assignments and hierarchies
- Validating role prerequisites before granting elevated permissions
- Implementing dynamic menu filtering based on role membership
- Automating role cleanup during employee termination processes
- Building role analytics for security auditing and optimization
Table Gotchas
The 'name' field is the role identifier used in gs.hasRole() and ACL conditions. Changing it breaks existing security rules. Always check dependencies before modifying role names in production.
Role hierarchy through 'contains_roles' is recursive. Creating circular references will cause infinite loops in role resolution. ServiceNow has some protection, but test hierarchy changes carefully.
- The
activefield doesn't immediately revoke access — users keep inactive roles until their session expires or they refresh their role cache - Querying by
descriptionis unreliable — it's often empty or generic. Usenamefor programmatic lookups - The
suffixfield affects role display names in lists and forms — blank suffix roles sort before suffixed ones regardless of alphabetical order
Role grants are additive. If a user has both 'incident_manager' and 'change_manager', they get permissions from both roles. There's no role exclusion mechanism — use conditional scripting instead.
- Performance trap: avoid joining
sys_user_roletosys_user_has_roletosys_userin large result sets — usegs.getUser().hasRole()for single-user checks
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.
Related Tables
The sys_user_has_role table creates the many-to-many relationship between users and roles, storing which roles each user possesses along with granted/inherited flags and inheritance tracking. The sys_user table connects through this relationship — you never directly reference sys_user_role from user records.
The sys_security_acl table frequently references roles in its condition scripts and role requirements, making these tables tightly coupled for access control. The sys_user_group table works alongside roles for comprehensive access control — groups provide data-level security while roles provide feature-level access.
Developers commonly join these tables when building user administration interfaces, generating security audit reports, or implementing complex authorization workflows. The sys_user_grmember table also appears in these queries since group membership often determines automatic role assignment through business rules and workflow.