Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

OnChange Catalog Clent Script

ID NOBLE
Tera Expert

Please I need help to resolve the following issue. We have OnChange Client Script that sets the value of NETWORK and MANUFACTURER ID fields when certain values are selected for Category and Subcategory fields respectively. It is actually working, but each time we change the Category and the subcategory fields to something different, the value of NETWORK and MANUFACTURER ID fields won't change. Your helps will be appreciated.

Thanks.

 

Below is the OnChange Client Script:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.clearValue('manufacturer_id');
var cat=g_form.getValue('category');
if(newValue=="sharepoint" && cat=="hardware")
{
g_form.setValue('manufacturer_id','N/A');
g_form.setValue('network','standalone');
}
//Type appropriate comment here, and begin script below

}

1 ACCEPTED SOLUTION

Allen Andreas
Tera Patron

Hi,

Your onChange client script, the one you posted above, will only work on ONE of the two fields that are involved here. Most likely, based off the script, you have the onChange client script only working on the subcategory field.

This means, if you change the category field, this onChange client script won't fire. You'd have to create one for onChange of category and one for onChange of subcategory. The "newValue" used in those client scripts refers to the newValue of the variable/field the onChange client script is set to run on. Meaning, if client script A is onChange of the category, then "newValue" is going to contain the new...value...of the category field.

The manufacturer_id and network fields will only change if the if statement before it....is true for both conditions. So you'd want to review that and ensure BOTH are true for the values of the manufacturer_id and network fields to be changed. Then also double-check your values to ensure N/A and standalone are appropriate values (they may be, but I just wanted to mention that you should check that).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

15 REPLIES 15

Hi Allen I have done that. Thanks.