Restrict selections in a dropdown choice field based on role

luke_paine
Kilo Contributor

Hi folks,

I'm trying to find out if i can restrict user access to a specific choice on a dropdown field based on role.

As part of my Change form, there is s section for close code (u_close_code) which is a preset number of selections.   I need to restrict one of the close code selections to all but users in the change_managers user group.

I'm not sure if its the right way to go about it, so far I have been attempting to do this by amending the existing ACL for the sys_choice table with a condition that the sys ID is not the ID of the selection i want restricted, and have created a new ACL rule with unrestricted table access for users with the change_managers role.   Needless to say, this hasn't worked.

I have run security debug for an itil user in the change form, but this is only showing logging around access the u_close_code field.

Can this be done, and if so am i on the right track or do i need to look elsewhere?

Regards,

Luke P.

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Use on load client script and make use of g_form.removeOption method to remove the choices as per your need.





Refer this section '4.8.8 Remove an option from a choice list'


http://wiki.servicenow.com/index.php?title=Client_Scripts#What_are_some_of_the_available_helper_func...


View solution in original post

8 REPLIES 8

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I would say that you can use some simple client script   to hide the choices you want.



Here is an example that we use to hide 2 states on a change if the change isn't approved:



function onLoad() {


      //Type appropriate comment here, and begin script below


      var approvalState =   g_form.getValue('approval');


      var changeType = g_form.getValue('type');


      if (!approvalState && !changeType)


              return;


      else if (approvalState != 'approved' && approvalState != 'rejected'){


              g_form.removeOption('state', '3');


              g_form.removeOption('state', '4');


      }


}



Let me know if there is any other questions



//Göran


luke_paine
Kilo Contributor

Thank you all for your quick and concise answers!



I have generated the following Client Script :



function onLoad() {


      //Type appropriate comment here, and begin script below


      var isChgMan =   g_user.hasRole('change_admin');


      if (!isChgMan)


              g_form.removeOption('u_close_code', 'cancelled');


      else if (isChgMan){


              return;


      }


}



That has done the trick. Much appreciated.


Hi Luke,

 

I have a requirement to restrict the problem closure based on role (problem manager) and group(with a prefix "xyz").

I was able to achieve this requirement partially i.e. for the role the restriction has been updated and works fine using below code. How do i add another condition to it for the second part i.e. group with prefix?

Any help would be really appreciated.

var isPrbMan = g_user.hasRole('Problem Manager');
if (!isPrbMan)
g_form.removeOption('state','6');
else if (isPrbMan) {
return;
}

 

Regards,

Surabhi

Vamsi Gudimalla
Kilo Explorer

Hi ,like the same senerio.

 

in incident table -what is impacted (we have 200 choice) and i want show only two choices based on the login user .

 

how to achieve this using  g_form.removeOption('u_close_code', 'cancelled');

 

Appreciate your quick help.

 

Regards

Vamis