GlideAjax.getXMLWait

TEJAS
Tera Contributor

Hi All,
I am facing a issue where when i run my onchange client script with calling function from script include , but using 

getXMLAnswer i am finding this error in the console
TEJAS_0-1742790644520.png

But in the on change client script i am not using GlideAjax.getXMLWait please see the below the script include and onchange client script 

##Script Include Code

var GetTableFields = Class.create();
GetTableFields.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getFields: function() {
        var tableName = this.getParameter('sysparm_table');
        if (!tableName) {
            return '[]';
        }

        // Get full parent table hierarchy
        var tables = this._getParentTables(tableName);

        gs.info('Fetching fields for tables: ' + tables.join(', ')); // Debugging log

        // Fetch fields from all related tables
        var ClientSideCall = [];
        var grDict = new GlideRecord('sys_dictionary');
        grDict.addQuery('name', 'IN', tables);
        grDict.addNotNullQuery('element'); // Only fetch actual fields
        grDict.query();

        while (grDict.next()) {
            var fieldName = grDict.getValue('element');
            var fieldLabel = grDict.getValue('column_label');
            gs.info('Found Field: ' + fieldName + ' - ' + fieldLabel); // Debugging log

            ClientSideCall.push({
                value: fieldName,
                label: fieldLabel
            });
        }

        return JSON.stringify(ClientSideCall); // Return as JSON string
    },

    _getParentTables: function(tableName) {
        var tables = [tableName]; // Start with the given table
        var parentSysId = null;

        var grTable = new GlideRecord('sys_db_object');
        grTable.addQuery('name', tableName);
        grTable.query();

        if (grTable.next()) {
            parentSysId = grTable.getValue('super_class'); // Get parent table sys_id
        }

        while (parentSysId) {
            var grParent = new GlideRecord('sys_db_object');
            if (grParent.get(parentSysId)) { // Fetch the actual table name
                var parentName = grParent.getValue('name');
                if (parentName) {
                    tables.push(parentName);
                    parentSysId = grParent.getValue('super_class'); // Get next parent
                } else {
                    parentSysId = null; // No more parents
                }
            } else {
                parentSysId = null; // No more parents
            }
        }

        return tables; // Return all parent tables
    },

    type: 'GetTableFields' // Required for Script Include
});

##Onchange client script
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var tableName = newValue;
    alert("Selected Table: " + tableName); // Debugging alert

    var ga = new GlideAjax('GetTableFields');
    ga.addParam('sysparm_name', 'getFields');
    ga.addParam('sysparm_table', tableName);
    ga.getXMLAnswer(function(response) {
        alert("Response from Script Include: " + response); // Debugging alert

        if (response) {
            var fields = JSON.parse(response);
            alert("Total Fields Found: " + fields.length); // Debugging alert

            g_form.clearOptions('condition_fields');
            g_form.addOption('condition_fields', '', '-- Select a Field --');

            fields.forEach(function(field) {
                g_form.addOption('condition_fields', field.value, field.label);
            });
        }
    });
}

And when i run background script i am able to see the expected field name 
this is the background script 

var gtf = new GetTableFields();
gtf.getParameter = function(param) {
    if (param === 'sysparm_table') return 'incident'; // Change to another table for testing
    return null;
};
var result = gtf.getFields();
gs.info('Final Result: ' + result);
TEJAS_1-1742790993427.png


My requirement is onchange of the table name i should get the selected table name field name 

Thanks in advance 
Regards 
Tejas K J





3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@TEJAS  

some other client script has that. Did you check that which other client script is running?

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 @Ankur Bawiskar 
I checked the other client script in the scope which i am working none of the script as GlideAjax.getXMLWait
And one more thing should i check all the client script which doesn't belong to my scope also 

@TEJAS  

this error comes for normal form or for catalog form?

if normal form, then check on that table which client scripts are running and if they have getXMLWait() irrespective of scope

If this is for catalog form then check any catalog client script applies to your item or any catalog client script which applies to variable set has that getXMLWait()

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