- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 01:51 AM - edited 09-22-2023 01:56 AM
Hi,
The code is correctly working when I used it just for email addresses, but for phone numbers, it is printing email address. Kindly help.
Glide Ajax
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("listCollectorEmailClass");
ga.addParam("sysparm_name", "listCollectorEmailFunction");
ga.addParam("sysparm_id", newValue);
ga.getXML(callBackFuntion);
function callBackFuntion(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue("s_email", answer);
g_form.setValue("s_phone", answer);
}
}
ScriptIncludes
var listCollectorEmailClass = Class.create();
listCollectorEmailClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
listCollectorEmailFunction: function() {
var userArr = this.getParameter('sysparm_id').toString().split(',');
var emailArr = [];
var emailArr1 = [];
for (var i = 0; i < userArr.length; i++) {
var grUser = new GlideRecord('sys_user');
if (grUser.get(userArr[i].toString())) {
var jsonObj = {};
emailArr.push(grUser.getValue('email'));
emailArr1.push(grUser.getValue("phone"));
}
}
return emailArr.toString();
},
type: 'listCollectorEmailClass'
});
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:39 AM
Hi @Community Alums,
Please create an object in the script include. Instead, emailArr = [] create retObj = {} object and then validate once.
Thanks and Regards
Anshul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:05 AM
Hello @Community Alums,
In the script include code you made a mistake, you are returning only emailArr and pushing phone in a different array (i.e., emailArr1).
Please use the below code for your reference:
Script Include:
var listCollectorEmailClass = Class.create();
listCollectorEmailClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
listCollectorEmailFunction: function() {
var userArr = this.getParameter('sysparm_id').toString().split(',');
var retObj = {};
for (var i = 0; i < userArr.length; i++) {
var grUser = new GlideRecord('sys_user');
if (grUser.get(userArr[i].toString())) {
retObj.email = grUser.getValue('email');
retObj.phone = grUser.getValue("phone");
}
}
return JSON.stringify(retObj);
},
type: 'listCollectorEmailClass'
});
Client Script:
I hope this will help you solve your problem. Please mark it as Accepted and Helpful.
Thanks and Regards
Anshul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:21 AM
Hi @anshul_goyal ,
I tried this, but it is not working. It is showing blank for both email and phone field.
var listCollectorEmailClass = Class.create();
listCollectorEmailClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
listCollectorEmailFunction: function() {
var userArr = this.getParameter('sysparm_id').toString().split(',');
var emailArr = [];
for (var i = 0; i < userArr.length; i++) {
var grUser = new GlideRecord('sys_user');
if (grUser.get(userArr[i].toString())) {
emailArr.email = grUser.getValue('email');
emailArr.phone = grUser.getValue("phone");
}
}
return JSON.stringify(emailArr);
},
type: 'listCollectorEmailClass'
});
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("listCollectorEmailClass");
ga.addParam("sysparm_name", "listCollectorEmailFunction");
ga.addParam("sysparm_id", newValue);
ga.getXML(callBackFuntion);
function callBackFuntion(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var retVal = JSON.parse(answer);
alert(answer);
g_form.setValue("regions_email", retVal.email);
g_form.setValue("regions_phone", retVal.phone);
}
}
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:39 AM
Hi @Community Alums,
Please create an object in the script include. Instead, emailArr = [] create retObj = {} object and then validate once.
Thanks and Regards
Anshul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:08 AM
In your script include you are storing the phone number in a separate array "emailArr1" which you are never returning to your client script, you are only returning "emailArr" - your email address array.
You might want to store both the email and phone number in an object, then push that into the one array.
(you have an obj variable defined already jsonObj, so you could store the phone number in jsonObj.phone and email in jsonObj.email then push that into the array)