getting error onChange script error: RangeError: Maximum call stack size exceeded function () { [native code] }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 04:13 AM
getting below error in the incident form
i have written on change client script, script is working fine but getting below error in the incident form
the script is related to converting the phone number after user entered it will automatically converted to phone number format as US.
script:
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading == false && (newValue != '' || newValue != null || newValue == oldValue)) {
var input = g_form.getValue('u_phone');
var formedPhone = formatPhone(input);
g_form.setValue("u_phone", formedPhone);
}
//Edits the phone number and sets the result on the form
function formatPhone(phoneEdit) {
var val = phoneEdit;
var ov = val;
var v = "";
var x = -1;
if (0 < ov.length && '+' != ov.charAt(0)) {
var n = 0;
if ('1' == ov.charAt(0))
ov = ov.substring(1, ov.length);
for (var i = 0; i < ov.length; i++) {
var ch = ov.charAt(i);
if (ch >= '0' && ch <= '9') {
if (n == 0)
v += "(";
else if (n == 3)
v += ") ";
else if (n == 6)
v += "-";
v += ch;
n++;
}
if (! (ch >= '0' && ch <= '9') && ch != ' ' && ch != '-' && ch != '.' && ch != '(' && ch != ')') {
x = i;
break;
}
}
if (x >= 0)
v += " " + ov.substring(x, ov.length);
}
return v;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 05:25 AM
Hi ram,
The main issue here is that this Client Script is presumably running on change of the Phone Number field, and the script is changing the same field, so it's running recursively until the error stops it. Secondary issues are that you're missing a digit at the end (US phone numbers are 10 digits), and this seems to be a way over-scripting solution. Start with this most basic script, then add anything that isn't meeting your requirements.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || newValue.substring(0,1) == '(') {
return;
}
var formedPhone = '(' + newValue.substring(0,3) + ')' + newValue.substring(3,6) + '-' + newValue.substring(6,10);
g_form.setValue('u_amount', formedPhone);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 04:20 PM
Were you able to test this solution to see if it meets your requirements?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 06:00 AM
Hi Ram,
This occurs when your oldValue and newValue changes continuously and thus in turn triggering the onChange() Client Script multiple times for the same field.
The easiest way to solve this issue is to write your code in a try-catch block.
Thanks,
Aniket Dey.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 06:58 AM
Can you help me on this???
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_scratchpad.user_group && g_form.isNewRecord()) {
//g_form.addOption('contact_type', 'sd-phone', 'SD-Phone');
g_form.setValue('contact_type','sd-phone');
}
}