Show/Hide choices of field based on selection of another field choice

Evan2
Kilo Guru

Hi Friends,

I an trying to show/hide choice of request type based on the choice selected for the field Select request Item on service portal.

Example:-

If Select request Item= Card Swipe Unit

then- Request Type should only show Install card swipe unit as choice.

PFB the screenshot for reference and help me how to achieve this.

find_real_file.png

Regards,

Evan

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Evan,

you would require onchange client script on the select item variable; sample script below

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading) {
      return;
   }

g_form.clearOptions('request_type');

if(newValue == 'Card Swipe Unit'){

g_form.addOption('request_type', choicevalue, choiceLabel);
g_form.addOption('request_type', choicevalue, choiceLabel);

}

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Namrata Khabale
Giga Guru

Hey Evan,

 

 

Write a onchange Client Script like Below and modify acording to your field names.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

 

    if (isLoading || newValue === '') {

 

          return;

 

    }

 

var getCategory = g_form.getValue('category');

 

  alert(getCategory);

 

  if(getCategory=='software')

 

  {

 

  alert('insde');

 

  g_form.removeOption('subcategory','os');

 

  }

 

Hit Correct and Helpful if it helps.

 

Thanks,

Namrata.

Hi Namrata,

 

Thank You for the efforts.I have changed the script as per my requirement but its not working. PFB the script I have used-

function onChange(control, oldValue, newValue, isLoading, isTemplate)
{
if (isLoading || newValue === '')
{
return;
}
var getCategory = g_form.getValue('select_request_item_GRHRCDIK');
alert(getCategory);
if(getCategory=='Card Swipe Unit')
{
alert('insde');
g_form.removeOption('request_type_GRHRCDIK','Install card swipe units');
}

}

 

Please help how to rectify.

Regards,

Evan