Restrict onChange script from executing on form load

A_112
Tera Contributor

Hi,

I have a catalog client script of type onChange. This script makes check in if condition and then throws a field message if check evaluates to true. Issue I am facing is that this field message is occurring when page loads.

Scenario:

I have a date field that pre-populates when page loads. This date is set to some date in future. I am maintaining this same date in a hidden date/time field as well. When user changes this date to even one day beyond the pre-populated date, user gets a field message info.

Basically when user changes the date, an onChange script on this date/time field executes and I do a comparison between this changed date and the original date which is also stored in hidden date/time field. If changed date is more than date in hidden field then the user sees the field message info. This scenario works fine.

But this field message info is also appearing when the form loads and sets the pre-populated date in the visible date/time field and hidden date/time field from back end table.

 

I referred to some solutions shared on community but no luck. I do not want this onChnage script to run when form loads.

Below are the articles I referred:

https://community.servicenow.com/community?id=community_question&sys_id=82964f25db1cdbc01dcaf3231f961901

https://community.servicenow.com/community?id=community_question&sys_id=67c88b61db5cdbc01dcaf3231f9619da

https://community.servicenow.com/community?id=community_question&sys_id=6e501729dbdcdbc01dcaf3231f961936

 

Thanks