How to display related record's Email Address (and have it work as an email field)

bsoremsugar —  June 14, 2013 — 1 Comment

This solution came from one of our great TSEs, Anthony Watson, as a part of something he was working on with a customer.

Step 1: Create a custom vardef that points to the related record, as shown in previous post,  HOWTO: Grab fields from a related record without Sugar Logic

Step 2: Add a ‘function’ entry to the above array that returns the email field html:

Save the above example as : custom/Extension/modules/Contacts/Ext/Vardefs/related_account_email.php

Step 3:

Notice that we are providing a path to a custom script that holds the function. While Sugar has a built-in function getEmailAddressWidget that returns the email field html, it expects the first parameter to be the bean object that you want to generate the email field from. As far as I can tell, there is not a way to force the vardef to pass the related bean object to the function, so we create an intermediary function to handle this:

Save the above as custom/getEmailAddressWidgetFromId.php to match the path value provided in the vardef.

After the above files are in place, do a Quick Repair & Rebuild and then move your new Account Email Address into the Display View layout via Studio. Note, you will likely see it as LBL_ACCOUNT_EMAIL until you update the label.

One response to How to display related record's Email Address (and have it work as an email field)

  1. 

    I would like to display a contact’s email address in a task that is related to that contact. Is there a way to use this code to grab the default email address from a contact and display it?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s