Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

On load Client script working on On change client script

sushma123vu
Tera Contributor

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

 

if (isLoading || newValue === '') {
        return;
   }

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!

4 REPLIES 4

sujitha16
Kilo Patron

@sushma123vu  Could you please share your complete script? I assume the problem would be because of having both "Else" and "newValue === ' ' ". 

 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

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.

    }

@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');

         }

 

 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Tai Vu
Kilo Patron

Hi @sushma123vu 

Let's double-check that if you have the isLoading variable as function parameters in your client script?

 

Cheers,

Tai Vu