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

Will I need to keep the default value under my variable name still that you provided earlier?

No. Whatever we have done so far is not needed. Just creating the above client script does your work.

Thanks

Okay so I have the catalog client script in but it is not pulling this info over.  Could it be that my user field is a custom field that is not included in the script?  

All the other info in the other catalog client script that I already had in the order guide is pulling the info over without any issues.

 

find_real_file.png

Can you please share the snapshot of whole client script as well.

This is the one that I have been using since our Onboarding has been live in the production environment.

function onChange(control, oldValue, newValue, isLoading) {

var employeeName = g_form.getReference(control.name, function(user){

//This will set the value of the fields on the OnBoarding describe needs page
g_form.setValue('u_ob_employee_userid', user.user_name);
g_form.setValue('u_ob_employee_firstname', user.first_name);
g_form.setValue('u_ob_employee_lastname', user.last_name);
g_form.setValue('u_ob_employee_jobtitle', user.title);
g_form.setValue('u_ob_employee_costcenter', user.cost_center);
g_form.setValue('u_ob_employee_location', user.location);
});

}

 

Here is the additional catalog client script that I created from what you provided me earlier:

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('u_ob_employee_mgr_email',user.email);
g_form.setReadOnly('u_ob_employee_mgr_email',true);
}}