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

you need to show what you have made, which is not working

-Anurag

Below is the code i returned.

find_real_file.png

If the user has 'itil' role and not 'app_service_admin' role then the 'additional_info' view should be visible. But its not working. The is visible to everyone. check below image.find_real_file.png

 

Hi,

Your end users should be able allowed to change views

Secondly, the else part in your scripts returning 'view', you don't have a view by that name, return a proper view there

Remove the Else if

 

-Anurag

Tried below code, still no Luck!!

(function overrideView(view, is_list) {

//Add your code here
var itilrole = gs.hasRole("itil");
var appserviceadminrole = gs.hasRole("app_service_admin");

if(itilrole && !appserviceadminrole)
answer = "additional_info";

else
answer = "default";

})(view, is_list);

After using above code now am able to see the views but can't select. only 'default' view i can select.