Unhandled exception in GlideAjax

Anish9515
Tera Contributor
function onChange(control, oldValue, newValue, isLoading) {
    // Check if loading or newValue is empty
    if (isLoading || newValue === '') {
        return;
    }

    // Create GlideAjax instance
    var ga = new GlideAjax('BISwCatDecomUtilAJAX');
    ga.addParam('sysparm_name', 'multilinetextversion');
    ga.addParam('sysparm_sys_id', newValue);

    // Use getXML method instead of getXMLAnswer
    ga.getXML(handleGlideAjaxResponse);
}

// Callback function to handle the response
function handleGlideAjaxResponse(response) {
   
        var answer = response.responseXML.documentElement.getAttribute("answer");

        alert("Suresh is " + answer);

        // Use meaningful variable names
        var multilineTextVersion = answer;
        alert("The input is " + multilineTextVersion);

        var parts = multilineTextVersion.split(/\),/);

        if (parts.length <= 1) {
        g_form.setDisplay('sw_cat_item_removed', true);
        g_form.setReadOnly('sw_cat_item_removed', true);
        } else {
            // If there are more than one part
        g_form.setDisplay('sw_cat_item_removed', false);
        }
    }
 
multilinetextversion: function() {
        var Productversion = [];
        var biproduct = [];

        var software = this.getParameter('sysparm_sys_id');
        var gr = new GlideRecord('u_biproductgroupingproduct');
        gr.addQuery('sys_id', software);
        gr.query();
        while (gr.next()) {

            var gr1 = new GlideRecord('u_biproduct');
            gr1.addQuery('sys_id', gr.u_product_id);
            gr1.query();
            if (gr1.next()) {
                biproduct.push(gr1.sys_id.toString());

                var gr2 = new GlideRecord('u_biproductversion');
                gr2.addQuery('u_product_id', 'IN', biproduct.toString());
                gr2.addEncodedQuery('u_product_version_status=Active');
                gr2.query();
                while (gr2.next()) {
                    Productversion.push(gr2.u_product_version_name.toString());
                }
            }
        }
        return Productversion.toString();
    },
 
Can anyone help me how to fix on this i got Unhandled exception in GlideAjax
Actually code is working fine i got java script browser console error
8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Anish9515 

try this

function onChange(control, oldValue, newValue, isLoading) {
	// Check if loading or newValue is empty
	if (isLoading || newValue === '') {
		return;
	}

	// Create GlideAjax instance
	var ga = new GlideAjax('BISwCatDecomUtilAJAX');
	ga.addParam('sysparm_name', 'multilinetextversion');
	ga.addParam('sysparm_sys_id', newValue);

	// Use getXML method instead of getXMLAnswer
	ga.getXMLAnswer(function(answer){

		alert("Suresh is " + answer);

		// Use meaningful variable names
		var multilineTextVersion = answer;
		alert("The input is " + multilineTextVersion);

		var parts = multilineTextVersion.split(/\),/);

		if (parts.length <= 1) {
			g_form.setDisplay('sw_cat_item_removed', true);
			g_form.setReadOnly('sw_cat_item_removed', true);
		} else {
			// If there are more than one part
			g_form.setDisplay('sw_cat_item_removed', false);
		}
	});
}

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

Suresh47_0-1700710293696.png

Suresh47_0-1700710751128.png

 

Still i got javascript console error 
Is it requires to change any script include?

 

whenever I added else part

else {
			// If there are more than one part
			g_form.setDisplay('sw_cat_item_removed', false);
		}

 i got javascript console error  

@Anish9515 

doesn't relate to script include.

try deactivating this client script and see if the exception still comes

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

I have noticed because of this client script only got "Java script console error" 

In Client script IF condition have only one "Software version" 

While add else condition i got console error because in else condition has multiple "software versions" separated by comma
In client script can we change into JSON format