onChange is firing twice on Service Portal Client Script

akaupisch
Kilo Guru

Not sure if this is a bug or if something else is going on that I'm unaware of.

I have a Date field on my RP which has an onLoad client script which sets the date to some point in the future.

I have an onChange Catalog Client Script which verifies a few things about that date.

  - If I use the date picker to select a date, it works fine.

  - If I manually change the date using the cursor and keypad (i.e. 7/20/2017 -> 7/21/2017 without using the date picker), the onChange is called 2 times.

I know the onChange isn't calling itself as I have commented out the code that does any sort of setValue.

Any thoughts? is this a known bug?

Easily reproducable, simply add a Date field (not DateTime) to a RP, add on onChange that does nothing more than alert(newValue), attempt to change the date without using the date picker. You'll see the alert called 2 times. This works totally fine in the form view.

1 ACCEPTED SOLUTION

Gurpreet07
Mega Sage

We faced this issue earlier and reported the same to Hi and it comes out to be a product defect and created a problem ticket for the same. We come up with a workaround of moving the onChange client script to onSubmit client script. Also try to add below condition in the script and check if its working fine by then.



if(newValue == oldValue){


return;


}


View solution in original post

3 REPLIES 3

Ajai S Nair
Giga Guru

Hi Adam,



In your onchange script ,


Do you have the below lines commented out removed ? If isloading is not there then it will execute both onload and onchange.



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


          return;


    }


Gurpreet07
Mega Sage

We faced this issue earlier and reported the same to Hi and it comes out to be a product defect and created a problem ticket for the same. We come up with a workaround of moving the onChange client script to onSubmit client script. Also try to add below condition in the script and check if its working fine by then.



if(newValue == oldValue){


return;


}


So I was able to keep in in the onChange, I did find that adding the newValue == oldValue into the isLoading if statement fixed it. Thanks