How to get Manager's name, email from a contact record?

Community Alums
Not applicable

Hi, 

I am trying to write a client script on change of "contact" record, I want to auto populate the fields like manager's name, email address etc. Manager field is a reference to sys_user table. 

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

  var contact = g_form.getReference('contact', callBack);
   
}
function callBack(contact)
{
	g_form.setValue('u_employee_last_name', contact.last_name);
	g_form.setValue('u_employee_first_name', contact.first_name);
	g_form.setValue('u_work_email_address', contact.email);
	g_form.setValue('u_manager_name', contact.manager);
	g_form.setValue('u_manager_first_name', contact.manager.first_name);
	g_form.setValue('u_manager_last_name', contact.manager.last_name);
    
}

Here is what I have so far and the results are turned out to be "undefined"

find_real_file.png

Please help. Thank you

1 ACCEPTED SOLUTION

Thanks for the detailed update.

Can you make your Manager (custom field) to be of type Reference instead of String.

If so, in the above script you need to comment last 2 lines where you set first name & last name.

Then get another onChage() client script written that takes the manager value & gets the first name & last name with the code similar to one you used above to get in Contact's first name & last name.

View solution in original post

10 REPLIES 10

Ashley Snyder1
Giga Guru

From your example it looks like the fields you're wanting to populate already exist on the Contact record, and a new set of fields have been created on the Case form. Since you have a reference field to the Contact record on the Case form, you should be able to display fields from the Contact on the Case form.  This way you don't have to create more fields on the form and populate them via scripts.  Be sure to make these fields read only on the form/list view via ACLs as you don't want users to change these values via the Case form, as it will change them on the Contact form.  

Try to limit the number of redundant fields in the system and teach users to use the pop-up for reference fields to view information.  Also try to limit scripting when possible, as these methods can usually be accomplished in other ways.