onChange script error: RangeError: Maximum call stack size exceeded function () { [native code] }

pramodkumar
Tera Expert

Hi All,

I have 2 checkboxes on a form and there are 2 onchange client scripts on each of them. Whenever I tried to make update it, I am getting below error

onChange script error: RangeError: Maximum call stack size exceeded function () { [native code] }

 

below is the script on checkbox1:

 if (isLoading || newValue == '') {
      return;
   }
var ch = g_form.getValue('checkbox2');
    if(ch == 'true'){
        g_form.clearValue('checkbox1');
        alert("Select only one");
 

below is the script on checkbox2

 if (isLoading || newValue == '') {
      return;
   }
var ch = g_form.getValue('checkbox1');
    if(ch == 'true'){
        g_form.clearValue('checkbox2');
        alert("Select only one");
7 REPLIES 7

@pramodkumar 

I would suggest you start from your side so that you will learn.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@pramodkumar Did you try the solution suggested by me?

Sandeep Rajput
Tera Patron
Tera Patron

@pramodkumar Inside the onChange script of Checkbox 1, you are checking if the checkbox 2 is already checked and then clearing the value of checkbox1 which is causing a recursive function call for the onChange client script for checkbox 1. You are doing the same thing for checkbox 2 as well and both of these scripts are causing infinite loop.

 

I recommend addressing this requirement via a UI Policy and its script field as follows.

 

1. UI Policy on Checkbox 1

Screenshot 2024-03-28 at 9.54.43 AM.pngScreenshot 2024-03-28 at 9.54.46 AM.png

2. UI Policy on Checkbox 2.

Screenshot 2024-03-28 at 9.55.23 AM.pngScreenshot 2024-03-28 at 9.55.37 AM.png

 

Do not forget to deactivate your onChange client scripts on checkbox 1 and checkbox2 before applying this solution.

 

Hope this helps.