Limit the values in a drop down field on the incident form, based on the value selected in a previous field

nomemon
Kilo Contributor

Is there a way to limit the values in a drop down field on the incident form, based on the value selected in a previous field on the incident form.

Eg: We have a field called Source with Values A, B, C, D

If A is selected, then the choices in the Location field should be 1, 2, 3

If B is selected, then the choices in the Location field should be 4, 5,6

3 REPLIES 3

Ken83
Mega Guru

Nomaan,



You can accomplish this by using an onChange Client Script. You will need to utilize the g_form.addOptions() and g_form.removeOptions to dynamically add or remove the options related to the choice in the previous field.



See here...


http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#addOption


GlideForm (g form) - ServiceNow Wiki


GlideForm (g form) - ServiceNow Wiki


nomemon
Kilo Contributor

Thanks Kenneth-


I wrote the following onChange Client Script:



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


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


          return;


    }


    //Type appropriate comment here, and begin script below


      if (g_form.getValue('impact' == 'Entire Bottler')){


              g_form.removeOption('urgency', 'Critical Business System');


      }


}



However, it still does not remove the 'Critical Business System' option from the urgency field, whenever Impact is selected as Entire Bottler.


Now, whenever i select the value from the Impact field, I get an error message "Script error encountered when changing this field - please contact your System Administrator".




You could try making the fields dependent on one another. The incident category and subcategory fields are out of the box as an example.



But the on change script will work too. The impact and urgency fields are integer fields so you need to specify the value in your script, not the display value:


Customizing Choice Lists - ServiceNow Wiki