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

Vishal Birajdar
Giga Sage

Hi @Community Alums 

 

In script include change  below line 

var json = new JSON().encode(jsonOBJ);

 To this..

var json = JSON.stringify(jsonOBJ);

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Community Alums
Not applicable

Still no luck.

 

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.stringify(answer);
		alert("op is " + op);
		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","" );
    }

}

 

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);
            var json = JSON.stringify(jsonOBJ);
            return json;
        }
    },

    type: 'getVendorInfoClass'
});

 

contacts.PNG

 

Regards

Suman P.

Hi Suman,

 

Try to put log in script include before return to check if you are getting value.

 

 gs.log("My value=" + json);

return json ;

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

KevinBellardine
Kilo Sage

Hey Dave,

Catalog client scripts have a slightly different syntax for setting variables vs setting form fields in a typical client script. You need to specify 'variables.variable_name', like this:

g_form.setValue("variables.vendor_technical_contact_name",op.callerName);
g_form.setValue("variables.vendor_technical_contact_phone",op.callerPhone);

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

are you sure phone is a valid field on company table?

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