Autopopulate logged in user's email

Community Alums
Not applicable

Hi,

I am trying to autopopulate the logged in user's email using business rule. It's not working. Kindly help.

 

1.png

 

2.png

 

3.png

 

(function executeRule(current, previous /*null when async*/ ) {

	current.email = gs.getUser().email;

})(current, previous);

 

Regards

Suman P.

13 REPLIES 13

Community Alums
Not applicable

Hi @Anand Kumar P,

 

This is working on the description field. How do I make it for the email field? It isn't plain text field.

 

1.png

 

2.png

 

(function executeRule(current, previous /*null when async*/ ) {

	current.description = gs.getUser().email;
	current.caller_id.email = gs.getUser().email;
	current.caller_id.email = gs.getUser().getEmail();
})(current, previous);

 

Regards

Suman P.

Abhishek_Thakur
Mega Sage

Hello @Community Alums ,

You can follow the below script in your BR, I have checked this script in my PDI it is working fine.

(function executeRule(current, previous /*null when async*/) {

	var curUser = gs.getUserID();
	var user = new GlideRecord("sys_user");
	user.addQuery("sys_id",curUser);
	user.query();
	if(user.next()){
		gs.log("Loggedin User Email is "+user.email);
		current.email=user.email;
	}

})(current, previous);

 

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

 

Regards,

Abhishek Thakur

Community Alums
Not applicable

Hi @Abhishek_Thakur,

 

That didn't work for me. Before posting it in the community, I exactly used it.

 

Regards

Suman P.

Hello @Community Alums ,

Then I would recommend using the display business rule along with the scratch pad that will help to bring the email id from server to client. So, that you can set that value in your form.

 

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

 

Regards,

Abhishek Thakur

Community Alums
Not applicable

Hi @Abhishek_Thakur,

 

That is a good one. I will try and post it here.

 

Regards

Suman P.