Restrict views based on role.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2020 01:33 AM
I had a requirement, based on roles the for views should be restricted. My requirement is if a user as 'itil' role, then he only 'additional info' view should be visible. Check below image.
I tried creating view rules with below code. But its not working. Please your inputs are appreciated.
(function overrideView(view, is_list) {
// Add your code here
if(gs.hasRole('itil')){
answer='additional_info';
}
else
answer = null; // set the new view to answer
})(view, is_list);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2020 09:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2021 02:47 AM
I am finding the same issue (using similar code to yours, I even tried adding "return answer;" to the code), however code that worked on our live Orlando instance does not work on a Personal Developer Paris instance adding in some gs.addErrorMessage statements shows that the viewoverride() code only runs when the view is default (""). I also had issues where the view choices disappeared unexpectedly - this was fixed by clearing the cache (type 'cache.do' into the Filter navigator).
However further investigation shows the reason for the issue is a simple "System Properties" setting under "UI Properties"...
Set "When a user changes the view used for a list or for a record, continue to use that view for future displays." to "No", the overrideView code is then run every time.