How to restrict view based on role?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 02:10 AM
I have one view called "Demo_View". I need to restrict this view only to users with Role "Viewers".
I tried adding role to view and adding view rule but it didn't work.
Please help me how can I achieve it. Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 02:15 AM
Hi,
so what script did you write?
share that
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 02:18 AM
(function overrideView(view, is_list) {
// Add your code here
var isSysAdmin = gs.hasRole("Admin");
var isViewer = gs.hasRole("Viewers");
if(isViewer && !isSysAdmin){
answer = "demo_view"; // set the new view to answer
} else{
answer = "default";
}
})(view, is_list);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 02:20 AM
Hi,
Don't test with admin role as admin will inherit all roles
with which role user you are testing?
are you sure name of view is correct? demo_view
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 02:23 AM
yeah i tried without admin 1st. It didn't work so I have added now. View name is correct only
.