Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to populate email ID for logged in user with Client Script ?

B Ashok
Tera Guru

How to populate email ID for logged in user with client script. 

 

I need to auto populate email ID in Catalog ITEM field. 

 

Thanks

Ashok

4 REPLIES 4

Jayant_M
Kilo Sage

Hi Ashok ,

you need to write script include with on change client script to fetch the value of email id.

 

Please mark my answer helpful if it resolves  your issue.

B Ashok
Tera Guru

Can you please provide the script. 

 

Thanks

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @B Ashok ,

 

Create a onload client script as below:

 

function onLoad() {
var user = g_user.userID;
var ga = new GlideAjax('populateUserEmailAddress');
ga.addParam('sysparm_name','getaddress');
ga.addParam('sysparm_user',user);

ga.getXMLAnswer(processResponse);

function processResponse(reposnse){
	alert('response is '+ reposnse );   // here you can set the value to any variable you want using g_form.setvalue()
}
}
   

 

 

Create a script include as below: (make sure it is client collable as per screenshot provided)

 

 

var populateUserEmailAddress = Class.create();
populateUserEmailAddress.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getaddress: function(){
		var userSysId = this.getParameter('sysparm_user');
		var gr = new GlideRecord('sys_user');
		gr.get(userSysId);
gs.info('email address is '+ gr.email + userSysId)
return gr.email;
	},
    type: 'populateUserEmailAddress'
});

 

 

See below screenshot for script include: 

SiddheshGawade_0-1704905144289.png

See below screenshot for client script:

SiddheshGawade_1-1704905182820.png

 

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh

Does this resolved you issue ? If yes, It would be great if you mark my response as CORRECT or Helpful so that others can see this on top of the list and get benefited by this.

 

Thanks & Regards,

Siddhesh