How to print(or show info msg) an array using getXMLAnswer method through client script?
- 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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 12:10 AM - edited 05-10-2024 12:12 AM
Well, there's some things that could be cleaned up, but I guess your biggest problems are related to the array you're using and you're trying to handle the response in a weird way on client side.
You could consider using your object logic instead
callerdetails: function() {
var callerId = this.getParameter('sysparm_caller');
var userObj = {};
var utable = new GlideRecord('sys_user');
utable.get(callerId);
if (utable.isValidRecord()) {
obj.phone = utable.getValue('mobile_phone');
obj.email = utable.getValue('email');
return JSON.stringify(obj);
}
return null;
},
Then handle the response in your client script:
function details(answer) {
if (answer) {
var responseData = JSON.parse(answer);
g_form.setValue("phone", responseData.phone);
g_form.setValue("email", responseData.email);
}
}
You should be able to use your array logic as well if you want.
Just end your script include with return obj.toString(); so that you're returning a string.
In your client script use
var res = response.split(","); to get an array of the values.
Your
var res = [response.toString()];
Is at the very least creating an array that has both values in the same index. Logging array you'd then have to separately add .toString() to it:
g_form.addInfoMessage('Hi'+res.toString());
Edit:
The last part probably answers your question, but I'd recommend using objects rather than arrays since they're more logical to handle and it's easy to access the values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 03:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 12:12 AM
Hello @KM SN
You can adding alert for Array and not the value in it. modify below lines
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 03:25 AM