How to hide a choice list value based on user role

Rhonda9
Tera Expert

Hello,

 

I am trying to hide a choice list value Category(category) on the work order form from a specific role.

I tried creating a onLoad client script but I must be doing something wrong because it is not working.

 
This is my script below which I am not good at.  Any assistance would be greatly appreciated.
 
function onLoad(){
 
if(g_user.hasRole('wm_security'))
 
 return;
        g_form.removeOption('category(category)', 'electrical');
 
}

 

 

Rhonda9_0-1705105945692.png

 

1 ACCEPTED SOLUTION

@Rhonda9 

uncomment the line number 6 and check logged user has role or not .

What it is giving . Is it true or false.

function onLoad() {
   //Type appropriate comment here, and begin script below
   
  var userRole = g_user.hasRoleExactly('wm_security'); 

 

   alert(userRole);

 

  if(userRole == true){
    g_form.removeOption('category','electrical');
  }

 

}

 

View solution in original post

21 REPLIES 21

Sandeep Rajput
Tera Patron
Tera Patron

@Rhonda9 Please update your script as follows.

 

 

function onLoad(){
 
if(g_user.hasRole('wm_security')){
g_form.removeOption('category', 'electrical');
}
}

 

Hope this helps.

Thank you for your response but it is not working.  I can still see electrical.

@Rhonda9 Could you please right click on the field name category(category) and confirm if the field name is category or something else?

Screenshot 2024-01-13 at 7.01.43 AM.png

It shows 'category'