- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2022 02:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2022 03:30 AM
Hi,
You can achieve in 2 ways
To display the all the fields when form loaded. We can use Display Business rule and onload client script to shows those field values.
1. create Display Business Rule with below code
(function executeRule(current, previous /*null when async*/) {
//using g_scratchpad variable store value and pass to client
g_scratchpad.mail = current.caller_id.email;
g_scratchpad.companyname = current.caller_id.company.name;
g_scratchpad.mobile = current.caller_id.mobile_phone;
g_scratchpad.managername = current.caller_id.manager.name;
})(current, previous);
2. create a onload Client Script with below code.
function onLoad() {
g_form.addInfoMessage("Caller's email is " +g_scratchpad.mail);
g_form.addInfoMessage("Caller's mobile number is " +g_scratchpad.mobile);
g_form.addInfoMessage("Caller's Company is " +g_scratchpad.companyname);
g_form.addInfoMessage("Caller's Manager Name is " +g_scratchpad.managername);
}
-----------------------------------------or------------------------------------------------------------
Create Display Business rule:
var mail = current.caller_id.email;
gs.addInfoMessage("this is email " +mail);
var companyname = current.caller_id.company.name;
gs.addInfoMessage("this is company " +companyname);
var mobile = current.caller_id.mobile_phone;
gs.addInfoMessage("this is mobile " +mobile);
var managername = current.caller_id.manager.name;
gs.addInfoMessage("this is manager " +managername);
Hope it helps!!
Please Mark ā Correct/helpful, if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2022 02:51 AM
Hi
Write before business rule like below.
current.email = current.caller_id.email;
current.company = current.caller_id.company;
current.mobile = current.caller_id.mobile;
current.manager = current.caller_id.manager;
Mark my answer as correct or hit like based on impact.
Regards
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2022 02:59 AM
--Mark the answer correct and helpful ------------
Hi,
try below code:-
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;
},
Hope this helps.
please mark my answer as ā
Correct & Helpful based on the validations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2022 03:10 AM
Hi,
seems one of your colleague already posted something similar question for which I have shared the answer
I assume you are talking about incident form; but you can enhance it for other tables
you can use display business rule on that table and show info messages
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.addInfoMessage('Caller email '+ current.caller_id.email);
gs.addInfoMessage('Caller colmpany '+ current.caller_id.company.name);
gs.addInfoMessage('Caller mobile '+ current.caller_id.mobile);
gs.addInfoMessage('Caller manager '+ current.caller_id.manager.name);
})(current, previous);
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-01-2022 03:30 AM
Hi,
You can achieve in 2 ways
To display the all the fields when form loaded. We can use Display Business rule and onload client script to shows those field values.
1. create Display Business Rule with below code
(function executeRule(current, previous /*null when async*/) {
//using g_scratchpad variable store value and pass to client
g_scratchpad.mail = current.caller_id.email;
g_scratchpad.companyname = current.caller_id.company.name;
g_scratchpad.mobile = current.caller_id.mobile_phone;
g_scratchpad.managername = current.caller_id.manager.name;
})(current, previous);
2. create a onload Client Script with below code.
function onLoad() {
g_form.addInfoMessage("Caller's email is " +g_scratchpad.mail);
g_form.addInfoMessage("Caller's mobile number is " +g_scratchpad.mobile);
g_form.addInfoMessage("Caller's Company is " +g_scratchpad.companyname);
g_form.addInfoMessage("Caller's Manager Name is " +g_scratchpad.managername);
}
-----------------------------------------or------------------------------------------------------------
Create Display Business rule:
var mail = current.caller_id.email;
gs.addInfoMessage("this is email " +mail);
var companyname = current.caller_id.company.name;
gs.addInfoMessage("this is company " +companyname);
var mobile = current.caller_id.mobile_phone;
gs.addInfoMessage("this is mobile " +mobile);
var managername = current.caller_id.manager.name;
gs.addInfoMessage("this is manager " +managername);
Hope it helps!!
Please Mark ā Correct/helpful, if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar