variable option hiding based on another variable options.

Aditya02
Tera Guru
function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   } var requestType = g_form.getValue(' request_type ');
    var mobileVariable = g_form.getControl('mobile');

 

    if ( requestType == 'new') {
        mobileVariable.removeOption (' Terminate' ,'terminate');
        g_form.setValue(' mobile ','new');
    } else if (requestType == 'terminate') {
        mobileVariable.removeOption('New','new');
        g_form.setValue('mobile', 'terminate');
    } else {
        mobileVariable.clearOptions();
        mobileVariable.addOption('new', 'New');
        mobileVariable.addOption('existing', 'Existing (number transfer required)');
        mobileVariable.addOption('terminate', 'Terminate');  
    }
}
 
 
Anyone correct this code .. i am getting this correctly.
if request type is new then terminate option has to be disappear in mobile variable. and new has to be default option for mobile variable.
if request type is terminate then new option has to be disappear in mobile variable. and terminate has to be default option for mobile variable.
3 REPLIES 3

Musab Rasheed
Tera Sage
Tera Sage

Hello,

As this is simple thing hence don't want to spoon feed you, kindly check below links you will get the idea. it's simple.

https://www.servicenow.com/community/developer-forum/hide-show-choice-list-in-client-script/m-p/2391...

https://www.basicoservicenowlearning.in/2023/08/servicenow-choice-list.html

https://www.servicenow.com/community/developer-forum/logic-to-show-hide-select-box-choices-based-on-...

Please hit like and mark my response as correct if that helps
Regards,
Musab
The question was asked on how to hide choice values on the Incident resolution code dropdown for 1 particular company. I show one way to accomplish this. In response to ServiceNow community question: ...

Pankaj kr
Kilo Sage

Hi Aditya,

 

Pls confirm where did you appied on change client script?

are terminate and new options of mobile variable?

also pls attach the screenshot of client screen page, and portal page for better understanding.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Pankaj Kumar

Pavankumar_1
Mega Patron

Hi @Aditya02 ,

can you validate the field name and choice value.

please see below examples

g_form.addOption(fieldname, choiceValue);
ex: g_form.addOption('state', '4');
g_form.removeOption(fieldname, choiceValue);
ex: g_form.removeOption('state', '5');

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar