How to get manager email for a logged-in user using javascript?

runfast
Kilo Guru

I am trying to populate a form with the logged in user manager email.   I can get the manager name using the manager ID but I am have a little bit of challenge getting the manager email address.

I found this article to get manager of manager. I tried to tweak it without any luck.

How can you get manager of manage of logged-in user as default value?

gs.getUser().getUserByID(gs.getUser().getManagerID()).getManagerID();

Any guidance or direction greatly appreciated.

thanks

Alex

2 ACCEPTED SOLUTIONS

christopheriron
Tera Expert

Hi Alex,



You will need to call a glide record for this, the below should work.



var manager = new GlideRecord('sys_user');


manager.get(gs.getUser().managerID);



manager.email



Thanks.


View solution in original post

var manager = new GlideRecord('sys_user');


manager.get(gs.getUser().managerID);


manager_email=manager.email;


View solution in original post

12 REPLIES 12

jyotis_
Giga Contributor

Hi Alex,

 

 

Use Script include code mentioned below:

getMEID: function(){

var mid = gs.getUserID();
var gr = new GlideRecord("sys_user");
gr.addQuery('sys_id', mid );

gr.query();
var meid = '';

if (gr.next()) {

meid = gr.manager.email;//.email;

}

return meid;
},

 

Client Script:

var ga = new GlideAjax('GetManagerEmail') ;
ga.addParam('sysparm_name','getMEID');
ga.getXMLWait();
alert(ga.getAnswer());

 

Thanks

Jyoti soni

siva_
Giga Guru

Hello runfast, 

You donot need to write any script for this 

OOB this is available using this way

 

var managerID = gs.getUser().getManagerID();

Hope this helps 

Mark the response as correct if that really helps so that others having the same question can find it easy

 

Thanks,

Siva

ANTONIO QUINTER
Kilo Contributor

Hi runfast, this worked for me very well.

javascript:gs.getUser().getUserByID(gs.getUser().getManagerID()).getRecord().getDisplayValue("email");

regards,

Tony.