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:48 AM
Hi @Community Alums
In script include change below line
var json = new JSON().encode(jsonOBJ);
To this..
var json = JSON.stringify(jsonOBJ);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 06:58 AM
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'
});
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:11 AM
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 ;
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:08 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:13 AM
@Community Alums
are you sure phone is a valid field on company table?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader