onChange Client Script to run only when certain variables have been populated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2019 08:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2019 10:17 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2019 10:26 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2019 02:38 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 10:57 AM
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.