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

Can we store multiple values in one gscratchpad

instead of creating multiple objects?