I have a Incident form if i select Caller field in Incident form then all the Fields like mobile number, location, name, Email Should be auto populate

kranthi2
Tera Expert

Hi,

I have a Incident form if i select Caller field in Incident form then all the Fields like mobile number, location, name, Email Should be auto populate.

Can any one help me out for the same.

Awaiting for your response,

Regards,

Sreenadh.

 

 

6 REPLIES 6

Indrajit
Mega Guru

Hey Kranthi,

g_form.getReference just ends up calling the client-side GlideRecord API. In my opinion, client-side GlideRecord should be avoided as much as possible, since it usually results in a lot of data being transferred needlessly. Its better if you use GlideAjax and script include.try below code,

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('ScriptIncludeName');//your script include name
ga.addParam('sysparm_name','populateUser');//your script include function name
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-----

Name: ScriptIncludeName

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;

},

Please Mark Correct and Helpful If you find my answer worthy.

Regards,

Indrajit.

Prateek kumar
Mega Sage

Here is an article that will help you:

https://community.servicenow.com/community?id=community_article&sys_id=53fa4b0adbd3cc1014d6fb2439961...

 

Please mark my response as correct answer and helpful if it helped solved your question.
-Best Regards
Prateek kumar


Please mark my response as correct and helpful if it helped solved your question.
-Thanks