undefined in glideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 05:08 AM
Script include
var PO_Details = Class.create();
PO_Details .prototype = Object.extendsObject(AbstractAjaxProcessor, {
returnDetails :function(){
var po = this.getParameter('sysparm_po');//from client script
var temp=this.getParameter('sysparm_temp');//from client script
var gr = new GlideRecord('u_po_form');//table name
gr.get(po);
var pobj = {};
pobj.recipient = gr.u_buyer_name.toString();
var grt= new GlideRecord('u_temp_form');//table name
grt.get(temp);
pobj.address = grt.u_buyer_address.toString();
return JSON.stringify(pobj);
},
type: 'PO_Details '
});
Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var po=g_form.getValue('u_po')//reference variable on catalog form
var temp=g_form.getValue('u_temp');//reference variable on catalog form
var ga = new GlideAjax('PO_Details');//Script include name
ga.addParam('sysparm_name','returnDetails');//standard code
ga.addParam('sysparm_po',po);//this will be used in script include, reference field
ga.addParam('sysparm_temp',temp);//this will be used in script include, reference field
ga.getXML(po_details);
function po_details(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('u_recipient_name', result.recipient);
g_form.setValue('u_recipient_address', result.address);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 05:53 AM
@Akki1 Try updating the script include code like below and check
var PO_Details = Class.create();
PO_Details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
returnDetails: function() {
var po = this.getParameter('sysparm_po'); //from client script
var temp = this.getParameter('sysparm_temp'); //from client script
var pobj = {};
var gr = new GlideRecord('u_po_form'); //table name
if (gr.get(po)) {
pobj.recipient = gr.u_buyer_name.toString();
}
var grt = new GlideRecord('u_temp_form'); //table name
if (grt.get(temp)) {
pobj.address = grt.u_buyer_address.toString();
}
return JSON.stringify(pobj);
},
type: 'PO_Details '
});
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023