View rule is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hello everyone, I have created a view called "Test view" which have only 4 fields and should be applicable to only list view, and this view should be visible to only users of group "Database". I created this view rule but it is not working? It is visible to all the users irrespective of groups
(function overrideView(view, is_list) {
if (is_list && gs.getUser().isMemberOf('Database')) {
answer = 'test_view';
}
})(view, is_list);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
try this
(function overrideView(view, is_list) {
if (is_list && gs.getUser().isMemberOf('Database')) {
answer = 'test_view';
} else {
answer = ''; // Ensures non-Database members get default view
}
})(view, is_list);
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
@Ankur Bawiskar , I tried your code but still Test view is visible to other users who are not part of Database group. Please see screenshots
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
These 2 things are working
1) when logged in user belongs to database group they are seeing the correct view?
2) when logged in user is not from database group they are seeing default view?
If both the above are working I believe we can't restrict showing the Test view in view changer.
If logged in user has view_changer role then they can switch view, but even if they switch the view rule will apply and take care.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
@Ankur Bawiskar Hi Ankur, I checked both points, Any logged in user irrespective of group they are able to see both view default as well Test view. What should I do to restrict Test view visibility for Database group users