- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2024 10:13 PM
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);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2024 11:37 PM - edited 12-22-2024 11:37 PM
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
---------------------------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2024 11:52 PM
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
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2024 11:24 PM
it's because it's going inside a loop.
you are validating the value with Regex and again setting it which in turns trigger client script
try this
var isUpdating = false; // Declare a flag
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || isUpdating) {
return; // Exit if the form is loading or if the script is already updating the field
}
var regex = /^(1[0-3]|[1-9])$/;
if (!regex.test(newValue)) { // Use regex.test() instead of regex.match()
g_form.showFieldMsg('xxx', 'Please enter a number between 1 and 13.', 'error');
isUpdating = true; // Set the flag before updating the field
g_form.setValue('xxx', 0);
isUpdating = false; // Reset the flag after updating the field
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 12:47 AM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2024 04:19 AM
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader