On load Client script working on On change client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 05:50 AM
My on-change script is working for on load also. I have tried below code to avoid that
if(isLoading){
return;
}
and also tried this
but yet it's not working.
Usually, my On change script is clearing the value when it doesn't satisfy certain condition. But this is being executed even onload. I don't want this to happen. Please help on this!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 11:16 PM
@sushma123vu Could you please share your complete script? I assume the problem would be because of having both "Else" and "newValue === ' ' ".
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 02:41 AM
Hi Sujatha and Timi,
Below is the script
if (isLoading || newValue == '') {
return;
}
var id1 = g_form.getValue('dummy1');
var id2 = g_form.getValue('dummy2');
var ga = new GlideAjax('script inlcude name');
ga.addParam('sysparm_name', 'function name');
ga.addParam('sysparm_pgmId', id1);
ga.addParam('sysparm_pgmServId', id2);
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != 'false') {
g_form.setValue('product_name', answer);
}
else {
g_form.clearValue('product_name');
}
I am setting value for the product name as "not valid" if any of id1/id2 description is having as security, else I will just clear off the value.
So this is being executing on load also, if the id1/id2 is not satisfying the condition its just clearing off the value.
Note: we are setting the values of all variables from on load so maybe that is triggering the on change not sure. But finally I dont want this code to execute on load.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 10:31 PM
@sushma123vu Why don't you combine onLoad script into onChange script itself for setting the values as below,
Kindly try with one script and check.
if (isLoading) {
g_form.setValue(<variable>, <value>;
}
var id1 = g_form.getValue('dummy1');
var id2 = g_form.getValue('dummy2');
var ga = new GlideAjax('script inlcude name');
ga.addParam('sysparm_name', 'function name');
ga.addParam('sysparm_pgmId', id1);
ga.addParam('sysparm_pgmServId', id2);
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != 'false') {
g_form.setValue('product_name', answer);
}
else {
g_form.clearValue('product_name');
}
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 11:48 PM
Hi @sushma123vu
Let's double-check that if you have the isLoading variable as function parameters in your client script?
Cheers,
Tai Vu