The Zurich release has arrived! Interested in new features and functionalities? Click here for more

View rule is not working

sunil10
Tera Contributor

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);

  

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@sunil10 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar , I tried your code but still Test view is visible to other users who are not part of Database group. Please see screenshotsScreenshot 2025-09-21 192830.pngScreenshot 2025-09-21 192716.png

@sunil10 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@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