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

@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.

tk37
Tera Contributor

@newhand 

Thank you for your generous support.
From your advice, I have discovered that there is a conflict in the View Rule.
The problem has been resolved. Thank you very much.

Jack
Tera Guru

Follow OOB View Rule as example for scripting:

/sysrule_view.do?sys_id=77a52fbe0fbf10103ff81b41ff767edd

Jack_0-1671595470714.png

(function overrideView(view, is_list) {
    var isAdmin = gs.hasRole("admin");
	var isLocationAgent = gs.hasRole("sn_esm_location_agent");
	var isRelationshipAgent = gs.hasRole('sn_customerservice.relationship_agent');
	
    if ((isLocationAgent || isRelationshipAgent) && !isAdmin) //check role here
		answer = "case"; //string
	else
		answer = view; //param


})(view, is_list);

Hope this help!

tk37
Tera Contributor

Thank you for your reply.

Based on the script you gave us, we tried the following, but unfortunately it did not work.

(function overrideView(view, is_list) {
    var isAdmin = gs.hasRole("admin");
	var isItsmCounter = gs.hasRole("u_itsm_counter");
	
    if (isItsmCounter && !isAdmin) //check role here
		answer = "ess"; //string
	else
		answer = view; //param


})(view, is_list);

Gurpreet07
Mega Sage

Hi,  There may be another view rule conflicting with this one. Apart from 'u_itsm_counter' ,user may have other roles assigned to him that is causing redirection to other view.