Need Help Restricting View Based on Role or Group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 09:10 PM
Hi Community,
I'm trying to restrict access to a custom view called "edit" on a specific table.
The requirement is:
Only show the "edit" view to users who:
- Have the role "xyz"
OR - Belong to the group "abc"
If the user does not meet either of these conditions, they should only see the default view, and the "edit" view should not be selectable or accessible.
Any help or guidance is appreciated!
Thanks,
Bishal Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 09:55 PM - edited 07-29-2025 09:58 PM
Hi @bishalsharm ,
This can be achieved with the help of View Rules in ServiceNow
I have created one view with the name "Edit "
Use case would be only 'itil' or users who are part of "Analytics Settings Managers" should able to see 'Edit' View and for other users the view should be 'default'
For this I have created View rule as below
System UI -> View Rules
Below is the script
(function overrideView(view, is_list) {
if (gs.hasRole('itil') || gs.getUser().isMemberOf('Analytics Settings Managers')) {
answer = 'Edit';
} else {
answer = 'default';
}
})(view, is_list);
Let's test this
I have impersonate user "Abraham Lincoln" who is part of "Analytics Settings Managers" group .
After impersonation . the user should able to see 'Edit' View
Note : to get backend name of view you can navigate to 'sys_ui_view' table
If my answer helped you, please consider marking it as ✅ Correct and giving it a 👍 Helpful — it might help other members in the community too!
Thanks,
Astik T 😊💡
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2025 08:59 PM
hi,
woulld it be possible to show both default and edit to users who all are either having the role or part of the group and to show only default who fails the condition ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 10:10 PM
you can use view rules for this.
What did you start with and where are you stuck?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader