null in GlideAJAX ScriptInclude

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 05:58 AM
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","" );
}
}
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'
});
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 06:18 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 06:29 AM
Hi @Mayur2109 ,
I did like this and I am getting the pop up, but the values are not populating in the fields.
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:29 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 06:23 AM
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'
});