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

MK-p
Tera Contributor

Getting below error in onchage client script.

 

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

 

code which i am using.

var regex = /^(1[0-3]|[1-9])$/;
    
    if (!regex.match(newValue)) {
        g_form.showFieldMsg('xxx', 'Please enter a number between 1 and 13.', 'error');
        g_form.setValue('xxx', 0); 
		
    }
2 ACCEPTED SOLUTIONS

Hey @MK-p ,

 

Clear Value clears value as well as messages related to the field, can you try adding error message post clearing value as below.

 

var regex = /^(1[0-3]|[1-9])$/;
    
    if (!regex.match(newValue)) {
        g_form.clearValue('xxx'); 
        g_form.showFieldMsg('xxx', 'Please enter a number between 1 and 13.', 'error');
    }

 

 

 

---------------------------------------------------------------------------------------------------

Please mark my answer as helpful/correct if it resolves your query.

Thanks,
Nilesh Wahule

---------------------------------------------------------------------------------------------------

 

View solution in original post

Hi @MK-p ,

 

Put clear message before field message.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

7 REPLIES 7

Runjay Patel
Giga Sage

Hi @MK-p ,

 

This is happening because it is your code is executing multiple time on onChange.

Either you can clear the filed or terminate the loop post error.

you can do like below.

var regex = /^(1[0-3]|[1-9])$/;
    
    if (!regex.match(newValue)) {
        g_form.showFieldMsg('xxx', 'Please enter a number between 1 and 13.', 'error');
        g_form.clearValue('xxx'); 
		
    }

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Hi @Runjay Patel ,

 

I need to display the message, after adding your suggestion error is not coming but message also not appearing.

Hey @MK-p ,

 

Clear Value clears value as well as messages related to the field, can you try adding error message post clearing value as below.

 

var regex = /^(1[0-3]|[1-9])$/;
    
    if (!regex.match(newValue)) {
        g_form.clearValue('xxx'); 
        g_form.showFieldMsg('xxx', 'Please enter a number between 1 and 13.', 'error');
    }

 

 

 

---------------------------------------------------------------------------------------------------

Please mark my answer as helpful/correct if it resolves your query.

Thanks,
Nilesh Wahule

---------------------------------------------------------------------------------------------------

 

Hi @MK-p ,

 

Put clear message before field message.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------