Show caller email id, company, mobile number and manager when form loads. Please give me an answer in Business Script?

Sai Mithra Siri
Kilo Contributor

Please help me 

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

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

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

5 REPLIES 5

Musab Rasheed
Tera Sage
Tera Sage

Hi @Sai Mithra Siripuram ,

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

Please hit like and mark my response as correct if that helps
Regards,
Musab

Service_RNow
Mega Sage

--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;

},

 https://community.servicenow.com/community?id=community_question&sys_id=ad9c03e5db9cdbc01dcaf3231f96...

Hope this helps.
please mark my answer as âœ… Correct & Helpful based on the validations.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

seems one of your colleague already posted something similar question for which I have shared the answer

https://community.servicenow.com/community?id=community_question&sys_id=28e1e556db2e4d50679499ead396...

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Pavankumar_1
Mega Patron

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

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar