View rule isn't working

Leonel Sandroni
Kilo Sage

I'm trying to filter views based on roles so I made a view rule with a script. It's the same script that most of users applied to filter views but in my case it's not working

role: Prueba_view_role
View: prueba_vista_roles

(function overrideView(view, is_list) {

	// Add your code here
	

	if (gs.hasRoleExactly('Prueba_view_role')){
		answer = "prueba_vista_roles";}
	
	
})(view, is_list);

I tried other alternatives (e.g. adding "else" part) but there was no solution.

I have a problem with the script or there is a problem with view rules?

1 ACCEPTED SOLUTION

Musab Rasheed
Kilo Patron

Hello,

hasroleexactly won't work here , you have to use HasRole only.

(function overrideView(view, is_list) {

	// Add your code here
	

	if (gs.hasRole('Prueba_view_role')){
		answer = "prueba_vista_roles";}
	
	
})(view, is_list);

hasroleexactly works with Client side and you have to use g_form.hasRoleExactly with client side whereas you have to use gs.hasRole with server side

 

View solution in original post

3 REPLIES 3

Musab Rasheed
Kilo Patron

Hello,

hasroleexactly won't work here , you have to use HasRole only.

(function overrideView(view, is_list) {

	// Add your code here
	

	if (gs.hasRole('Prueba_view_role')){
		answer = "prueba_vista_roles";}
	
	
})(view, is_list);

hasroleexactly works with Client side and you have to use g_form.hasRoleExactly with client side whereas you have to use gs.hasRole with server side

 

It's a piece of cake...haha!!! Thanks, now it's working!!!

Ankur Bawiskar
Tera Patron

Hi,

hasRoleExactly() is not a valid function on gs object

use hasRole()

(function overrideView(view, is_list) {

    // Add your code here
    if (gs.hasRole('Prueba_view_role'))
        answer = "prueba_vista_roles";

})(view, is_list);

Regards
Ankur