The CreatorCon Call for Content is officially open! Get started here.

onChange client script with templates and dependent choice lists

shill
Mega Sage

I have a couple of onChange client scripts that run when the category and subcategory of an incident change.

What I am needing to do is exclude these from running when a template changes either one of these fields.

 

It looks as if an onChange client script set to a dependent choice list will fire twice, once when the parent choice is made (I assume by the setting of the choices) and once when the field itself is changed.

Because of this, I am only able to stop one 'cycle' of the script by using the isTemplate check.

 

How can I stop the client script from running the second time on the subcategory field when a template is used?

9 REPLIES 9

casey_stinnett
Giga Expert

I hope that I understood your problem correctly, because I tried duplicating your error on a Eureka version (ServiceNow) by putting a client script with an alert on the subcategory. Then I changed the category and the script did not run.



Might something in your script be causing it to run twice? I can't really evaluate it without seeing your script.


Here is my onChange script for the subcategory field that I am using as a test case.



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


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


  return;


}


alert("subcat fired");


}



If I use a template that sets the category and subcategory, I get the alert.


If I use a template that only sets either the cat or subcat, I do not get the alert.


This only seems to occur when I am setting both values.



In my tests on a demo site, I was able to duplicate if my template was setting both values.


Sanjeev Kumar1
Kilo Sage

Hi,


I think you need to check for template in subcategory onchange script also.



If it's not help you please provide your script and scren short of you page.


Yes, it makes sense to check for a template in both.