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

Thanks always Allen. I will do just that.

Thanks always Allen. I will do just that. For clarification purpose, the condition is that if category is HARDWARE and subcategory is SHAREPOINT, then make manufacturer_id equals to "N/A" and at the same time, make network equals to "standalone". Does the above explanation make it more understandable please?

Hello @ID NOBLE 

I see you've marked a reply as Correct. I'm glad you found an answer.

I don't think it's very clear what you ended up doing, especially since you've asked the same question to multiple people after the fact.

If you still need assistance, please let me know.

If you don't, please at least let us know what you did to resolve your issue.

Thanks and take care! 🙂


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

Hi Allen, I posted that because someone mentioned that he didn't understand the requirement, maybe wasn't clear enough. So that's why I posted the other explanation for better understanding of the requirements.

Hi @ID NOBLE 

So your issue is now resolved?

If so, what did you do to resolve it.

Thanks!


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