We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

onChange client script on 2 different fields interact with each other causing an error

Dave65
Tera Contributor

Thanks in advance for your help!

I have 2 fields one takes a percentage of the base pay for an increase and the other takes a dollar amount of the increase.

We want the user to be able to fill one of the fields in and the onChange script will make the calculation to fill in the other.

The problem that I'm having is that if both scripts are Active, they trigger each other and then I get the following error:
onChange script error: SyntaxError: Invalid regular expression: /(^|[\x20\t\r\n\f])form-field([\x20\t\r\n\f]|$)/: Stack overflow function () { [native code] }

The information I've been able to find indicates that I'm running into Recursion. The suggested solution was to add newValue === oldValue as follows:

 if (isLoading || newValue === '' || newValue === oldValue) {
              return;
}
 
I've done that and it doesn't work. I even tried it with == instead.
 
I'd appreciate any suggestions.
 
Thanks!
 
Dave
0 REPLIES 0