onChange Client Script to run only when certain variables have been populated

danielbartholom
Mega Expert

Hi,

I am trying to get this working on a catalog client script so it works via the Service Portal. I have the current onChange Client Script which calls a script include to pull data back to another variable (ci_test) which is working great. This is how it works:

You select something from a variable called amend_ci and the client script kicks in and populates data back to the variable ci_test. Here is the Client Script:

onChange
Variable: amend_ci

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var ga = new GlideAjax('getRelAppParent') ;
ga.addParam('sysparm_name','getApp');
ga.addParam('sysparm_app',newValue);
ga.getXML(hello);

function hello ()
{
var answer = ga.getAnswer();
//alert(answer);
g_form.setValue('ci_test',answer); //network_path is your variable where you want to store path


}

}

Is there something I can add to this script to only run the GlideAjax when another variable on the form is populated (rel_test) this is what I was trying to no avail 😞

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if(g_form.getValue('rel_test', 'Applicative Flow To (parent)')){

var ga = new GlideAjax('getRelAppParent') ;
ga.addParam('sysparm_name','getApp');
ga.addParam('sysparm_app',newValue);
ga.getXML(hello);
}

function hello ()
{
var answer = ga.getAnswer();
//alert(answer);
g_form.setValue('ci_test',answer); //network_path is your variable where you want to store path


}

}

 

basically I don't want the Client Script to run unless the amend_ci is populated and rel_test is populated with a particular value.

Any assistance would be most appreciated 

  

8 REPLIES 8

Thank you,

 

I will give this a go and get back to you with results

 

Thanks again for your help so far. It's really appreciated

 

 

 

Please note that you cannot make the onchange script to wait till the other field is populated. If you want that to happen, then you might have to have that other field populated first and then have your field inputted.

Hey

Any update on this?

If one of the responses provided above answered your question, please mark the response as correct so that others in the future can find it quickly and that it gets removed from the unanswered list.

Simran Reddy
Kilo Explorer

Hi  Daniel,

i have the same requirement and was thinking to use 2 separate onChange client scripts for those two fields which triggers the Script include. How did you make it work? Any inputs would be great.

Thank you.