- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 07:29 PM
How to auto populate caller email and caller phone number whenever select caller in catalog item?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 07:54 PM
---Mark the answer correct and helpful ------------
Backend field names change it accordingly
Onchange client script
field: Caller
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.setValue('caller_phone','');
g_form.setValue('caller_email_address','');
//Type appropriate comment here, and begin script below
}
else
{
var ga = new GlideAjax('ATQInfo');
ga.addParam('sysparm_name','populateUser');
ga.addParam('sysparm_user',newValue);
ga.getXML(UserInfo);
}
}
function UserInfo(response)
{
var answer2 = response.responseXML.documentElement.getAttribute('answer');
var ans3 = answer2.split(",");
//alert('Answer:'+ans3);
if(answer2 != ''){
g_form.setValue('caller_phone',ans3[0]);
g_form.setValue('caller_email_address',ans3[1]);
}
}
--------Script Include-----
Client callable --> true
populateUser: function(){
var mbphone='';
var email='';
var phone='';
var user1 = this.getParameter('sysparm_user');
//gs.addInfoMessage('sys_id' + user1);
var gr1=new GlideRecord('sys_user');
gr1.addQuery('sys_id',user1);
gr1.query();
if(gr1.next())
{
phone = gr1.phone;
email = gr1.email;
//gs.addInfoMessage('returing' + mbphone + ',' + phone + ',' + email);
}
return phone + ',' + email;
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 07:47 PM
Hi,
This would be very simple. Create an onchange script on caller field and, fire a glideAjax call in script and pass the caller's sys_id(g_form.getValue()).
Create the script include, get the caller's sys_id (passed via glideajax), query user table and return the matching value in an array.
In client script, get the returned value and set tit to respective variables 🙂
see couple of examples https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference/r_ExamplesOfAsynchronousGlideAjax.html

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 07:54 PM
---Mark the answer correct and helpful ------------
Backend field names change it accordingly
Onchange client script
field: Caller
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.setValue('caller_phone','');
g_form.setValue('caller_email_address','');
//Type appropriate comment here, and begin script below
}
else
{
var ga = new GlideAjax('ATQInfo');
ga.addParam('sysparm_name','populateUser');
ga.addParam('sysparm_user',newValue);
ga.getXML(UserInfo);
}
}
function UserInfo(response)
{
var answer2 = response.responseXML.documentElement.getAttribute('answer');
var ans3 = answer2.split(",");
//alert('Answer:'+ans3);
if(answer2 != ''){
g_form.setValue('caller_phone',ans3[0]);
g_form.setValue('caller_email_address',ans3[1]);
}
}
--------Script Include-----
Client callable --> true
populateUser: function(){
var mbphone='';
var email='';
var phone='';
var user1 = this.getParameter('sysparm_user');
//gs.addInfoMessage('sys_id' + user1);
var gr1=new GlideRecord('sys_user');
gr1.addQuery('sys_id',user1);
gr1.query();
if(gr1.next())
{
phone = gr1.phone;
email = gr1.email;
//gs.addInfoMessage('returing' + mbphone + ',' + phone + ',' + email);
}
return phone + ',' + email;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 08:40 PM
Hi Ram,
Please find this below link if you want to auto-populate logged in user's details:
Autopopulate Logged in user details
If you want to populate depending on "Change of Caller", then Script include will remain same, except you will have to create 1 onChange Client script as suggested by Chalan in above post.
Please mark my answer as Correct/Helpful in case that helped you somehow.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 08:50 PM
Write a onchange catalog client script and call the script include.
In on change catalog client script get the caller id and call the script include using GlideAjax and pass the caller id as a sysparam_callerId.
In script include glide the User table and get the email and caller phone number and put them in an array and return the array.
Then in onChange() catalog client script get the array in callback function and set the values on the required field.
Please mark it helpfull/correct in case that is helpfull.
Thanks