Restrict views based on role.

Divya57
Tera Expert

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.

find_real_file.png

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

11 REPLIES 11

Because only that is allowed.

What do you want changed now?

If you want users to not see the view list itself you need to make sure they don't have the view changer role

find_real_file.png

 

 

-Anurag

neilpetertuffs
Tera Contributor

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.