How can a person with a specific role access the View? (View Rule not working)

tk37
Tera Contributor

I would like to allow a person holding a specific role to access the following View.

(I want to allow role holders to access other people's ess views.)
・Table : sys_user
・View : ess
・Role : u_itsm_counter

 

I created the following View Rule Script, but it did not work.
I would appreciate anyone's help.

 

・Script

(function overrideView(view, is_list) {
answer = view;
if (gs.hasRole('u_itsm_counter')) {
answer = "ess";
}
})(view, is_list);

1 ACCEPTED SOLUTION

@tk37 

Finally i found the reason.

If a user selected a view manually. 

This selection will be the first priority.

 

Set the test user's view to "default view" and test it !

 

Please mark my answer as correct and helpful based on Impact.

View solution in original post

15 REPLIES 15

p t1
Kilo Sage
Kilo Sage

tk37
Tera Contributor

Hi Preethi,

 

Thank you for your reply.
I have already seen the URL you gave me and if I follow the script example, I think it would be as follows, but this did not work either.

 

(function overrideView(view, is_list) {
if (!gs.hasRole("u_itsm_counter"))
{return;}
answer = "ess";
})(view, is_list);

 

Thanks,

tk37

newhand
Mega Sage

HI @tk37 

 

 

have a try with   using  the glideUser 's hasRole function  instead.

 

var currentUser = gs.getUser();

currentUser.hasRole('u_itsm_counter')

 

 

Please mark my answer as correct and helpful based on Impact.

tk37
Tera Contributor

Hi newhand,

 

Thank you for your reply.

I followed your advice and modified the following Script, but it does not work.
If there is something wrong with my Script, could you please advise?

 

(function overrideView(view, is_list) {
var currentUser = gs.getUser();
if(!currentUser.hasRole('u_itsm_counter'))
{return;}
answer = "ess";
})(view, is_list);

 

Thank you,

tk37