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

Not yet. Although it's still setting the values correctly for the condition that when Category equals to Hardware, and Subcategory equals to Sharepoint then Network value should be "Standalone", and Manufacturer_id should be "N/A". But the issue is that when category and subcategory fields are changed, "Network" and "Manufacturer_id" stays the same instead of changing to the value of the new selection from category and subcategory. Is my explanation clear enough to help solve the problem please?

Thank you once again Allen. I have now resolved it. Just as you mentioned earlier, I created another client script for Category field and then added: g_form.clearValue for both manufacturer_id and network fielsse respectively.

Hi @ID NOBLE 

Great 🙂

Please mark the appropriate reply as Correct for the one that guided you towards resolution.

Thank you!

Please also mark any other replies as "Helpful" if they were.

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


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

This helps a lot in resolving the problem. Thank you Allen.

Hi @ID NOBLE 

Great 🙂

Please mark the appropriate reply as Correct for the one that guided you towards resolution.

Thank you!

Please also mark any other replies as "Helpful" if they were.

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


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