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

Mahalakshmi Rav
Tera Contributor

When the sample number field is filled, Escalation Manager should auto populate based on the sample number field values. The sample number has different managers and it is stored in sample_data_1 table. I have written a script include and on change client script to populate the value based on the sample number selection but its not working. 

Errors which I'm facing for this script:

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

2. The escalation manager field is auto populating for a while and getting vanished. 

3. If the sample data is filled and changed, the escalation manager value is not populating. 

MahalakshmiRav_0-1742281661265.png


Script Include:

 
var EscalationManagerUtil = Class.create();
EscalationManagerUtil.prototype = {
   
    // function to get Escalation manager based on the sample  number

    getEscalationManager: function(sampleNumber) {
        var gr = new GlideRecord('sample_data_1'); // Create a GlideRecord object to query the table
        gr.addQuery('sample_number', sampleNumber); // Filter records where 'u_sample_number' matches the input
        gr.query();

        if (gr.next()) { // Check if a matching record is found
            return gr.getValue('escalation _manager'); // Get and return the 'escalation _manager' field value
        }

        return ''; // Return an empty string if no matching record is found
    },

    type: 'EscalationManagerUtil' // Define the class type
};
 

On change client script:

function onChange(control, oldValue, newValue) {
   
    // When the sample data is empty, clear the Escalation Manager field

    if (!newValue) {
        g_form.clearValue('escalation _manager');
        return;
    }

    // This GlideAjax object will call the EscalationManagerUtil script include
    var ga = new GlideAjax('EscalationManagerUtil');

    //  calling the getEscalationManager function in the script include
    ga.addParam('sysparm_name', 'getEscalationManager ');
    // sending the selected sample Number as a parameter
    ga.addParam('sysparm_sampleNumber', newValue);

    // Call the Script Include and process the response
    ga.getXMLAnswer(function(response) {
        g_form.setValue('escalation_manager', false); // Set the escalation Manager field with the response
    });
}
 
 
 
 
 
8 REPLIES 8

Hi @Ankur Bawiskar , You're right it's a scoped application and both script include, client script in the same scope. 
My on-change client script is partially working which means the escalation manager field is auto populating for few seconds and getting vanished. 

@Mahalakshmi Rav 

Did you check this?

Seems your client script is setting "escalation_manager" which in turn is triggering another client script and hence it's causing some recursion

did you check that?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Mahalakshmi Rav ,

 

In Client script you are calling "EscalationManagerUtil" Script Include and above screenshot is of  TerritoryManagerUtil() script include. Just cross check which one you want to call and also see if "EscalationManagerUtil" is client callable if this is the script include you wish to call from Client Script.

Hi @Rohit Singh , 

I was replicating the scenario on my PDI and I double-checked that the "EscalationManagerUtil" Script Include is being called and it's client callable.