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

I will try this solution and let you know the outcome after I come back from my lunch break!  

Thanks so much for your help!

Hi Archana,

I have everything in the script include but it still didn't work.  Do I need to set the manager's variable field to a reference or leave as a single line text field?

Thanks,

Terry 

Hi Terry,

I know I am very late in asking this. Please let me know if your order guide looks something like this.

find_real_file.png

u is Reference Field where you are selecting User and

mail is the single line text field that needs to be populated with manager's mail.

Am I correct?

Thanks

Yes, that is a solution that I'm looking for.  The reason I'm struggling is that the manager email field is not a field that is available out of box so I'm trying to find a way somehow to pull this in from the user table as that manager would have a email address associated with their name.

 

Thanks for clearing my doubts.

Am not sure if Script Include works for this or not. Lets go with onChange catalog client script.

Make sure you select correct Order Guide and set Variable name to YouruserField

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var user = new GlideRecord('sys_user');
user.addQuery('sys_id',newValue);
user.query();
if(user.next())
{
var man = user.manager;
 user.get(man);
	g_form.setValue('mail',user.email);
	g_form.setReadOnly('mail',true);
	}}

Replace mail with mgr_email.

Hope this helps!

Thanks