Retrieving Requester(caller_id) Email address / company information etc. on a client side Script

Community Alums
Not applicable

Hi,

How would I retrieve Requester email information which is displayed under the float when checking additional information ('i') on a requester in a incident.

It seems to be defined id="sys_readonly.sys_user.email" under the float, is there a way to refer directly to the information like in g_user.userName or is there a way to refer to it some other way? I have tried searching online for solutions but I seem to be hitting a dead end here.

Please let me know if additional information is required or if I'm being unclear

1 ACCEPTED SOLUTION

OK, thanks.


So, in the incident script:


Type: onLoad


Script:


function onLoad() {



var email = g_form.getReference('caller_id', setEmail);



function setEmail(email) {


if (email)


alert('email is '+ email.email);


g_form.setValue('short_description', email.email); //this changes the short_description, but change it to populate the right field, or remove it if you do not need it.


}


}



For the catalog task, you can use:


Again, an onLoad client script:


function onLoad() {


    //Type appropriate comment here, and begin script below



var email = g_form.getReference('request_item.request.requested_for', setEmail);


    }



function setEmail(email){


alert('email ' + email.email);


g_form.setValue('short_description', email.email); //this changes the short_description, but change it to populate the right field, or remove it if you do not need it.


}



harel


Edit:


I just noticed that I have the requested for field on my catalog task form. If you don't have it or don't want to add it, you will need to use a GlideAjax call in a client script and a script include:


Client script:


Table: sc_task


Type: onLoad


Script:


function onLoad() {


    //Type appropriate comment here, and begin script below



var ri = g_form.getValue('request_item');



var ga = new GlideAjax('getEmail'); //this is the script include


ga.addParam('sysparm_name', 'userEmail'); //this is the function within the script include


ga.addParam('sysparm_ri', ri);


ga.getXML(getResponse);



function getResponse(response) {


var values = response.responseXML.documentElement.getAttribute('answer');



alert(values);



}


}



Script include:


Name: getEmail


Client callable: yes


Script:


var getEmail = Class.create();


getEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {



userEmail : function() {



var ri = this.getParameter('sysparm_ri');



var req =   new GlideRecord('sc_req_item');


req.addQuery('sys_id', ri);


req.query();


while(req.next()) {


return req.request.requested_for.email;


}


},


      type: 'getEmail'


});


harel


View solution in original post

10 REPLIES 10

Community Alums
Not applicable

Perfect!



Thanks once again for a quick reply and solution! I think I should be able to work with this knowledge quite a bit and be able to apply it where it's needed.