Removing Option from the Choice list

Kaleem A
Giga Guru

Hi All,

I have two fields on the form "Category" and "Subcategory".   Subcategory is dependent on Category field. Here I'm trying to remove the option from the subcategory based on the option selected in the category field.   I have onChange Client script as below. It doesn't seem to be working. Can someone help me on this.

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

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

      return;

    }  

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

  if(incident_category == 'Proactive'){

  g_form.removeOption('subcategory','system generated');

  }

}

1 ACCEPTED SOLUTION

johansec
Tera Guru

I don't understand why you cannot do this by updating the dependent values in the choice list.



System generated should not be depended on Proactive but instead something else.


View solution in original post

8 REPLIES 8

The only downside to this is maintainability. If you ever change the choice list, you will also have to change the hardcoded values in the script.


varunnprasaad
Giga Contributor

Hi Akbar,



Please go through the following article by Mark Stranger on ServiceNow Guru.


It was really helpful for me.



https://www.servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-opt...


RAHUL Khanna1
Mega Guru

Also Dependent Logic Executes Later than Client SCript .....so CS is not affecting in any ways.

Ivan16
ServiceNow Employee
ServiceNow Employee

Hi Kaleem,

 

Follow this KB as a workaround

=> https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1641021

 

Thanks