Auto-populate the manager's e-mail address

Terry Carter Jr
Tera Contributor

Hello All,

I am trying to find a easy and good solution to populate the manager's email address of a user from the sys_user table in a custom variable field for a service catalog item.  The name of the variable field is "mgr_email" and I want to pull the manager's e-mail address in this field.  I am currently working on an order guide for Onboarding/Offboarding so this is one of the business requirements on the catalog items attached to it.    

I have tried various solutions on the community but none seem to work properly or there are so many examples that it overwhelms you to which one should be the right answer.

Any help or assistance would greatly be appreciated. 

Thanks,

Terry   

1 ACCEPTED SOLUTION

Then, select "New Team Member Name"  at the highlighted area.

find_real_file.png

View solution in original post

25 REPLIES 25

Vivek,

 

Yes, we have on the first page of the order guide where the manager will select a user from the reference and from there I want it to pull that users manager's email. 

 

Thanks,

Terry

Archana Reddy2
Tera Guru

Hi Terry,

Create a Script Include named getEmail as below. Make sure the pre-populated script in script include is erased and paste it there.

function getEmail()
{
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',gs.getUserID());
user.query();
if(user.next())
{
var man = user.manager;
return man.email;
}
}

Set default value of mgr_email variable to javascript:getEmail()

The above script works if you are trying to get Logged-in user's manager email. Let me know if I somehow misunderstood the question.

Thanks

Hi Archana,

 

Thanks for your reply as well.

I'm not trying to get the logged-in users manager but I am trying to get the user selected on the referenced field manager.  

For example if I have a variable "Who is it for?", I would want to pull that user's manager that is in this field on the order guide.

Thanks,

Terry Carter

 

 

I meant that manager's email address and populate it on the form.

Just few updates to the above post by which I feel we can achieve this requirement.

function getEmail(gr)
{
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',gr);
user.query();
if(user.next())
{
var man = user.manager;
return man.email;
}
}

Default Value:javascript:getEmail(current.variables.VARIABLENAME);

Hope this helps!

Thanks