On Incident form trying to auto populate the email of caller in Email Id field using Script include

Rishi9128
Tera Contributor

I am trying to Auto populate the email of Caller in a Email ID field by using Script include and client script, but only a pop is coming up with a "Null".

 

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var callerdetails = g_form.getValue('caller_id');
 
    var ga = new GlideAjax('getcallerEmail'); 
    ga.addParam('sysparm_name', 'callerEmail');
    ga.addParam('sysparm_callerid', 'callerdetails');
    ga.getXML(getResult);
 
    function getResult(response) {
var answer =response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
g_form.setValue("u_email_id",answer);
    }
 
 
}
 
Script Include:
var getcallerEmail = Class.create();
getcallerEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
    callerEmail: function() {
 
        var test = this.getParameter('sysparm_callerid'); // getting sys_id
        var inc = new GlideRecord('sys_user');
        inc.addQuery('sys_id', test);
        inc.query();
 
        if (inc.next()) {
gs.log('email is '+ inc.email);
            return inc.email;
        }
    },
 
 
    type: 'getcallerEmail'
});
4 ACCEPTED SOLUTIONS

Craig Gruwell
Mega Sage

Hi @Rishi9128,

 

Try changing:

ga.addParam('sysparm_callerid', 'callerdetails');

 

to:

ga.addParam('sysparm_callerid', callerdetails);

View solution in original post

Community Alums
Not applicable

Hi Rishi,

 

You can refer to the below video where it has been explained to get Email ID of the Caller. As well as, use the same Script Include function to return phone number of the Caller. 

 

 

To learn about basics of GlideAjax, refer to this video.

 

Please mark this comment as Helpful/Correct Answer if it helped you.

 

Cheers,

Hardit Singh

View solution in original post

DanielCordick
Mega Patron
Mega Patron

I think you issue lies in this line

 

ga.addParam('sysparm_callerid', 'callerdetails');

 

its sending the string ‘caller details’ instead of the sys id,  remove the ‘’ that should fix. Also add some logging to your script include to see what’s getting passed over

View solution in original post

Vishal Birajdar
Giga Sage

Hi @Rishi9128 

 

Just a suggestion...!!

 

You can get an email field of caller in incident by dot walking.

Configure the form layout and get Email id field by dot walking.

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

5 REPLIES 5

Craig Gruwell
Mega Sage

Hi @Rishi9128,

 

Try changing:

ga.addParam('sysparm_callerid', 'callerdetails');

 

to:

ga.addParam('sysparm_callerid', callerdetails);

Community Alums
Not applicable

Hi Rishi,

 

You can refer to the below video where it has been explained to get Email ID of the Caller. As well as, use the same Script Include function to return phone number of the Caller. 

 

 

To learn about basics of GlideAjax, refer to this video.

 

Please mark this comment as Helpful/Correct Answer if it helped you.

 

Cheers,

Hardit Singh

DanielCordick
Mega Patron
Mega Patron

I think you issue lies in this line

 

ga.addParam('sysparm_callerid', 'callerdetails');

 

its sending the string ‘caller details’ instead of the sys id,  remove the ‘’ that should fix. Also add some logging to your script include to see what’s getting passed over

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @Rishi9128 ,

Actually, this is the Out-of-the-box feature, no need to write any code for it.

Just add the Caller.email field from the Form layout

1. Right-click the form header to open the form context menu, select configure -> Form layout, Select Caller[+] from the available bucket, and double-click on it, to expand caller fields.

2. select the email field from the available bucket under the caller field and add it to the selected bucket (it adds caller.email field to the available bucket) and save it.

 

it automatically populates the caller's email ID after selecting the caller name

 

Please mark my answer correct & helpful, if it helps you

Thank you

 

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer