Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...
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

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

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

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

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

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...