- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 04:50 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 04:58 AM
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
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 04:58 AM
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
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:16 AM
It's a piece of cake...haha!!! Thanks, now it's working!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:02 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader