null in GlideAJAX ScriptInclude

Community Alums
Not applicable

Hi,

I am getting null for GlideAJAX answer value. Kindly help.

 

GlideAJAX

 

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

    var ga = new GlideAjax("getVendorInfoClass");
    ga.addParam("sysparm_name", "getVendorInfoFunction");
    ga.addParam("sysparm_VenID", newValue);
    ga.getXML(callBackFunction);
	alert("new value is " + newValue);

    function callBackFunction(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		var op = JSON.parse(answer);
		alert("answer is " + answer);
		g_form.setValue("vendor_technical_contact_name",op.callerName);
        g_form.setValue("vendor_technical_contact_phone",op.callerPhone);
	//	g_form.setValue("vendor_technical_contact_email","" );
    }

}

 

GlideAJAX.PNG

 

ScriptInclude

 

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

    getVendorInfoFunction: function() {
        var param = this.getParameter("sysparm_VenID");
        var compCode = new GlideRecord("core_company");
        compCode.addQuery("sys_id", param);
        compCode.query();
        if (compCode.next()) {
            var jsonOBJ = {};
            jsonOBJ.callerName = compCode.getValue("name");
            jsonOBJ.callerPhone = compCode.getValue("phone");
            //	jsonOBJ.callerEmail = compCode.getValue("u_asset_classification");
            var json = new JSON().encode(jsonOBJ);
            return json;
        }
    },

    type: 'getVendorInfoClass'
});

 

ScriptInclude.PNG

 

Regards

Suman P.

10 REPLIES 10

Mayur2109
Kilo Sage
Kilo Sage

Hi @Community Alums ,

Change line in client script from 

 

var op = JSON.parse(answer);

 

to 

 

var op = JSON.stringify(answer);

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,
Mayur Shardul

 

Community Alums
Not applicable

Hi @Mayur2109 ,

 

I did like this and I am getting the pop up, but the values are not populating in the fields.

 

GlideAJAX.PNG

 

ScriptInclude.PNG

 

Regards

Suman P.

Hi @Community Alums ,

 

I tried it with parse again it worked for me please check again with code I have provided.

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

    var ga = new GlideAjax("getVendorInfoClass");
    ga.addParam("sysparm_name", "getVendorInfoFunction");
    ga.addParam("sysparm_VenID", newValue);
    ga.getXML(callBackFunction);
	alert("new value is " + newValue);

    function callBackFunction(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		var op = JSON.parse(answer);
		alert("answer is " + answer);
		g_form.setValue("description",op.callerName);
        g_form.setValue("short_description",op.callerPhone);
	//	g_form.setValue("vendor_technical_contact_email","" );
    }

}
var getVendorInfoClass = Class.create();
getVendorInfoClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getVendorInfoFunction: function() {
        var param = this.getParameter("sysparm_VenID");
        var compCode = new GlideRecord("table_name");
        compCode.addQuery("sys_id", param);
        compCode.query();
        if (compCode.next()) {
            var jsonOBJ = {};
            jsonOBJ.callerName = compCode.getValue("field_name");
            jsonOBJ.callerPhone = compCode.getValue("field_name");
            var json = new JSON().encode(jsonOBJ);
            return json;
        }
    },

    type: 'getVendorInfoClass'
});

 

Regards,

Mayur Shardul

 

Mike Patel
Tera Sage

Try below

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

    var ga = new GlideAjax('getVendorInfoClass');
    ga.addParam('sysparm_name', "getVendorInfoFunction");
    ga.addParam('sysparm_VenID', newValue);
    ga.getXMLAnswer(function(answer) {
        if (answer != '' && answer != null) {
            var response = JSON.parse(answer);
            g_form.setValue("vendor_technical_contact_name", response.callerName);
            g_form.setValue("vendor_technical_contact_phone", response.callerPhone);
        }
    });
}
var getVendorInfoClass = Class.create();
getVendorInfoClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getVendorInfoFunction: function() {
        var param = this.getParameter("sysparm_VenID");
        var compCode = new GlideRecord("core_company");
        compCode.addQuery("sys_id", param);
        compCode.query();
        if (compCode.next()) {
            var jsonOBJ = {};
            jsonOBJ.callerName = compCode.getValue("name");
            jsonOBJ.callerPhone = compCode.getValue("phone");
            return JSON.stringify(jsonOBJ);
        }
    },
    type: 'getVendorInfoClass'
});