HOWTO: Grab fields from a related record into your DetailView

sugarcrmdevelopers —  January 26, 2012 — 11 Comments

Editor’s Note: The solution posted below works great for adding one field from a single module, but really struggles to scale when you want to grab many fields from different modules, or show these fields on a listview. For that reason, check out this post for a better way to do this.

Ran across a great forums post the other day, that is a common request I’ve seen before.

Hi All!

I have created some custom fields in the Leads Module.

When the Lead is converted, at least, I would like to have that custom Lead information show up on the Opportunity Module with the Lead data. How can I achieve this?
For us, the Opportunity is directly related to the Lead.

Thanks in advance for your help 

This is something that is very easy to do with Sugar Logic in Sugar 6.3. In that release, we introduced a related() function, which will look in a related module to grab a field value and put it in the given field. So to solve this problem, all you need to do is add a custom field that is calculated with the following equation ( assuming you want to grab the lead name ).


You can then add this field to any DetailView or ListView and it will show the related record’s data.

11 responses to HOWTO: Grab fields from a related record into your DetailView

    Matias Barletta January 26, 2012 at 5:25 pm

    John thanks for the tip. Do you mind specify whether this works on all versions or just sugar professional versions?



    Sounds interesting!

    2 questions :
    1) Is it only starting at release 6.3 and earlier ?
    2) Can you point me to a tutorial or info about how to create a custom calculated filed ?


    Bernardo Romero January 27, 2012 at 9:22 pm

    Thanks for the tip. What if I want to add up the values in all related fields (the fields are all of Integer type)



    The actual calculation only appears to happen in the EditView (or on Save).
    Is there an easy way to force the calculation to occur on the DetailView (and ListView)?


      Whenever the related record changes, it will update the record that has the calculated field as well. (Unless the ‘disable_related_calc_fields’ config option is set)

    GalacticDomin8r April 6, 2012 at 4:01 pm

    I have a custom module I would like to grab fields from.  How  does one go about find the equivalent of “$leads” for a custom module?


    Very useful guide! Thanks for sharing.  related function is really a great edition !


    Hi, Is there a way of grabbing the related fields of a grandparent module.
    I have Accounts -> Opportunities -> Tasks. I need to display the account name on the task… I can show the related opportunity name but not the related account name.

Trackbacks and Pingbacks:

  1. SugarCRM Developer Blog » Blog Archive » HOWTO: Grab fields from a related record without Sugar Logic - March 13, 2012

    […] of you will remember this blog post from a few weeks back, where I showed you how to add a field from a related module by leverage […]

Leave a Reply

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

You are commenting using your 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