How to print(or show info msg) an array using getXMLAnswer method through client script?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 11:45 PM
I just want to send two details of caller to an array and bringing them back to client script and there using Client script i need to show the array whenever the caller field changes. but i am getting msg as below and i am adding script too.
Client Script:
var cid = g_form.getValue('caller_id');
var ga = new GlideAjax('gettingcallerdetails');
ga.addParam('sysparm_name','callerdetails');
ga.addParam('sysparm_caller', cid);
ga.getXMLAnswer(details);
function details(response){
//var res = JSON.parse(response);
var res = [response.toString()];
g_form.addInfoMessage('Hi'+res);
}
Script Include:
var gettingcallerdetails = Class.create();
gettingcallerdetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
callerdetails: function() {
var abc = this.getParameter('sysparm_caller');
//var obj = {};
var obj = [];
var utable = new GlideRecord('sys_user');
if (utable.get(abc)) {
//obj.phone = utable.getDisplayValue('mobile_phone');
//obj.email = utable.getDisplayValue('email');
obj.push(utable.getDisplayValue('mobile_phone'));
obj.push(utable.getDisplayValue('email'));
gs.addInfoMessage('SC :' + obj);
}
// return JSON.stringify(obj);
return obj;
},
type: 'gettingcallerdetails'
});
6 REPLIES 6
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 12:37 AM
Hi @KM SN ,
I'm able to solve your problem in my PDI please check below
Client script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var cid = g_form.getValue('caller_id');
var ga = new GlideAjax('gettingcallerdetails');
ga.addParam('sysparm_name', 'callerdetails');
ga.addParam('sysparm_caller', cid);
ga.getXMLAnswer(details);
function details(response) {
var res = JSON.parse(response);
g_form.addInfoMessage('Hi' + res);
}
}
Script Include :
callerdetails: function() {
var abc = this.getParameter('sysparm_caller');
//var obj = {};
var obj = [];
var utable = new GlideRecord('sys_user');
if (utable.get(abc)) {
var mobile = utable.getDisplayValue('mobile_phone')+"";
var email = utable.getDisplayValue('email')+"";
obj.push(mobile);
obj.push(email);
gs.addInfoMessage('SC :' + obj);
}
return JSON.stringify(obj);
},
Result
Please mark my answer correct and helpful if this work's for you
Thanks and Regards
Sarthak
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 03:28 AM