When incident record is opened, caller Id’s email should visible in the top of the form

prakhar_yadav
Tera Contributor

Hi Community,

 

When incident record is opened, caller Id’s email should visible in the top of the form. How to achieve it

 

Thanks,

Prakhar

1 ACCEPTED SOLUTION

debendudas
Mega Sage

Hi @prakhar_yadav ,

The best practice to achieve this functionality is by using the g_scratchpad.

debendudas_3-1725709165432.png

 

 

Please follow the below steps to configure this:

  • Create a Display Business Rule as below
    debendudas_0-1725708902568.png
    debendudas_1-1725708928536.png

 

(function executeRule(current, previous /*null when async*/ ) {
	
	if(current.isNewRecord()){
		return;
	}
	
	// Populating the g_scratchpad value with the Caller's Email id
    g_scratchpad.caller_email = current.caller_id.email.getValue();

})(current, previous);

 

  • Create a onLoad Client Script as below

     

    debendudas_2-1725709082757.png

 

function onLoad() {

	if(g_form.isNewRecord()){
		return;
	}

	// Displaying Caller's Email in a Info messgae
	if(g_scratchpad.caller_email){
		g_form.addInfoMessage("Caller's Email: " + g_scratchpad.caller_email);
	}
   
}​

 

 

View solution in original post

3 REPLIES 3

debendudas
Mega Sage

Hi @prakhar_yadav ,

The best practice to achieve this functionality is by using the g_scratchpad.

debendudas_3-1725709165432.png

 

 

Please follow the below steps to configure this:

  • Create a Display Business Rule as below
    debendudas_0-1725708902568.png
    debendudas_1-1725708928536.png

 

(function executeRule(current, previous /*null when async*/ ) {
	
	if(current.isNewRecord()){
		return;
	}
	
	// Populating the g_scratchpad value with the Caller's Email id
    g_scratchpad.caller_email = current.caller_id.email.getValue();

})(current, previous);

 

  • Create a onLoad Client Script as below

     

    debendudas_2-1725709082757.png

 

function onLoad() {

	if(g_form.isNewRecord()){
		return;
	}

	// Displaying Caller's Email in a Info messgae
	if(g_scratchpad.caller_email){
		g_form.addInfoMessage("Caller's Email: " + g_scratchpad.caller_email);
	}
   
}​

 

 

Sandeep Rajput
Tera Patron
Tera Patron

@prakhar_yadav Here are the steps, using which you can add caller Id's email on top of the incident form.

1. Configure the form layout

Screenshot 2024-09-07 at 5.20.54 PM.png

Search the caller field in the slush bucket in the Available fields side.

Screenshot 2024-09-07 at 5.16.10 PM.png

Click to expand the related fields and choose email and take it to the selected fields section

 

Screenshot 2024-09-07 at 5.17.14 PM.png

This is how it should look when taken to the right side.

 

Screenshot 2024-09-07 at 5.18.06 PM.png

Adjust the position of the caller.email to top of the form.

 

Save the changes and this is how it looks when the layout is saved.

Screenshot 2024-09-07 at 5.18.18 PM.png

 

Please mark the response an accepted solution if it addresses your question.

Abhishek_Thakur
Mega Sage

Hello @prakhar_yadav ,

As per the best practices, you can use client callable script include & client script.

 

Script Include;

var GetEmail = Class.create();
GetEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    demoTest: function() {
        var user = this.getParameter("sysparm_caller_id");
		var gr = new GlideRecord('sys_user');
		gr.addQuery("sys_id",user);
		gr.query();
		if(gr.next()){
			return gr.email;
		}
    },
    type: 'GetEmail'

});

 

Client script;

function onload(){
var ga = new GlideAjax('GetEmail');
   ga.addParam("sysparm_name","demoTest");
   alert("test");
   ga.addParam("sysparm_caller_id",g_form.getValue("caller_id"));
   alert("test1");
   ga.getXML(callback);
   function callback(response){
	alert('test');
	var answer = response.responseXML.documentElement.getAttribute("answer");
	alert("Email is " +answer);
}

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.