Hiding Radio buttons

kunal16
Tera Expert

Is there any way to hide radio button (question choice under a MULTIPLE CHOICE variable type) for business users (non-ITIL users)?

3 REPLIES 3

moulik1
Kilo Guru

You can check below threads and see if its helpful.



https://community.servicenow.com/thread/174593


Service Catalog Requirement


Hi Moulik,


Thanks for the threads. But since my requirement is more of a user-role specific, UI policies wont work out. I tried the below client script and it removed the whole multiple choice variable including label from the service catalog.



function onLoad() {


  var isitil = g_user.hasRole('itil');


  if (!isitil)


  {


  var a = g_form.getControl('safe_request_type');


  var b   =$(a).up(1).up(1).childElements().each(function(value,index){ if(value.innerHTML.indexOf('Architecture') != -1){ $(value).hide(); }     });


  }


}



Since, I need only one radio button (from the list of 3 radio button choices) to be invisible for non-ITIL, the above script doesn't seem to work.


Stephen W_
Giga Guru

I know this is a very old question, but I thought I'd chime in, just in-case someone else is looking for the answer.


Unfortunately ServiceNow hasn't given us an easy option, but here's what you need:




//This assumes that your variable is named "safe_request_type" and your option value is "architecture"


function onLoad() {


    if (!g_user.hasRole("itil")){


          showRadio("safe_request_type","architecture",false);


    }


    function showRadio(strVarName, strOption, bVisible){


          var myOptions = g_form.getControl(strVarName).up(1).getElementsByTagName("label");


          for (var i=0;i<myOptions.length;i++){


                var element = myOptions[i].getElementsByTagName("input")[0];


                if (element.value == strOption){


                      element.hidden=!bVisible;


                      myOptions[i].hidden=!bVisible;


                      break;    


                }


          }


    }


}