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

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