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

Community Alums
Not applicable
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (!newValue) {
        g_form.clearValue('u_caller');
        g_form.clearValue('u_email');
        g_form.clearValue('u_location');
        return;
    }
    var cal = g_form.getReference('u_caller', getCall);

    function getCall(cal) {

        g_form.setValue('u_email', cal.email);
        g_form.setValue('u_location', cal.location);
     
    }
}
I'm trying to auto populate caller details using callback function , its displaying the values but the function enters into recursive/infinite loop , how to rectify the script error ?
1 REPLY 1

Bert_c1
Kilo Patron

try adding:

 

    if (isLoading || newValue === '') {
        return;
    }

at the top of onChange function, before the 'if (!newValue) {' (I suspect that line is a problem, why would the onChange client script run if there is no newValue? See:

 

client-scripts

 

check OOG onChange client scripts for working examples.