Display Form View based on roles wise

Kishore8
Kilo Guru

i have create one view with name " Emergecny" this view should be visible for only ITIL role users only.

for that i have written View Rule script. but it is effecting to admin, it should not be effect to admin persons and other role persons ,

it should effect only to ITIL role users only

12.png

122.png

1 ACCEPTED SOLUTION

leebooth
Kilo Expert

You can add another check in to not apply for admin roles:



if (!gs.hasRole('admin')) {


        if (gs.hasRole('itil')) {


                  answer = "Emergency"


        }


}


View solution in original post

4 REPLIES 4

Dhravesh Murpan
Mega Expert

Create the below function and utilize it for checking what all role user has



function hasRoleExactly(role) {
  var au = new ArrayUtil();
  var roles = gs.getSession().getRoles() + '';
  var roleArray = roles.split(",");
  var isAuthorized = au.contains(roleArray, role);
  return isAuthorized;
}



or may check client side script


GlideUser (g user) - ServiceNow Wiki


Hi,



i would like to see this view only when view user field set: Abraham Lincoln ,


1.png


leebooth
Kilo Expert

You can add another check in to not apply for admin roles:



if (!gs.hasRole('admin')) {


        if (gs.hasRole('itil')) {


                  answer = "Emergency"


        }


}


Hi Lee,



it is working,


can i ask once concern here please , this is last.



i would like to see this view for ITIL users when view users filed   value is : "Abraham Lincoln"     other wise it should show normal form     means View should not effect




1.png