Add custom field in the subpanel from relationship table


We all know that we have the  Many to Many relationship from Opportunities to Contacts by default in Sugar. So one Contact can have multiple Opportunities and similarly, one Opportunity can have multiple contacts.
So let us see an example how the role field in the subpanel plays a vital role here.

  1. Each Opportunity can be related to one or more contacts that are displayed in the subpanel on the Opportunities record view. The Contacts subpanel allows users to select an opportunity-specific role (e.g. Primary Decision Maker, Business Evaluator, etc.). Based on the role of the contact, will help us to decide how the individual contact will be the factor into the buying decision for the current Opportunity.
  2. The same contact can be linked to multiple Opportunities and can have different roles for each specific opportunity. In this case we cannot create the field in the studio in the Contact. This role field should be only for Opportunity Subpanel.

Now in this blog, let us learn how to create the field in the subpanel from the relationship table. Let us take an example creating the dropdown field in the Members(custom module) subpanel under the Meetings Module. We have many to many relationship between the Meetings and Members module. Every meeting can have many members and Every member can attend multiple meetings. In this case the role field helps us a lot where we can store the status of the Member whether he attended a particular meeting or not. When we create M-M relationship between two modules it creates the metadata file and also relationship files in vardefs in both the modules. Now as it is a relationship field we cannot create this field through the studio or module builder. It has to be done through code. To do this we have to add small snippets of code in a few files.

Step – 1

  1. We have to create the field in the subpanel module where the field should be shown.We have to add the field in the metadata file as mentioned below. For adding this field in the subpanel please add the below code as mentioned in the below path,

Note: We have to add this in the fields array in this file.

'meeting_status' =>
   array (
   'name' => 'meeting_status',
   'type' => 'enum',  

Note: The path of the file may vary based on the relationship, Usually it will be ./custom/metadata/{link_name}MetaData.php

Step – 2

We have to add the field in the relationship file also. When an M-M relationship is created it creates a file in the Members module as well as in the Meetings module in the Vardefs path.
Now we have to add this code in the below path at the end of the file.

'rel_fields' =>
    'meeting_status' =>
      'type' => 'enum',
      'options' => 'meeting_status_type_list'

Step – 3

As we want to see the status of the member for the meeting. Let us create a dropdown field called Meeting Status in the Members module.
For this create the file in the below path.


$dictionary['PSME_Members']['fields']['meeting_status']['importable']=  false;
$dictionary['PSME_Members']['fields']['meeting_status']['link']= 'meetings_psme_members_1';
$dictionary['PSME_Members']['fields']['meeting_status']['rname_link']= 'meeting_status';

Let us understand a bit about the parameters used in this code.

  1. As we want to create the dropdown field the data type of the field is ‘enum’.
  2. 2. When we have created the relationship between two modules it creates a link parameter. So we have to give the link name for the link.
  3. As it is a dropdown field we have to add options parameters and then give the name of the dropdown list created for this field.
  4. PSME_Members module refers to the module name.

Step – 4

For the dropdown field, we have to create the dropdown list ‘meeting_status_type_list’ as mentioned in the above file. For this, you have to add a small snippet of code in the below path.


$app_list_strings['meeting_status_type_list']=array (
  'Selected' => 'Selected',
  'Invited' => 'Invited',
  'Accepted' => 'Accepted',
  'Rejected' => 'Rejected',
  'Attended' => 'Attended',
  'Absent' => 'Absent',

Step – 5
Once all these files are in place, we have to perform the Quick Repair and Rebuild by going to the Admin section in the Sugar Instance.
Note: Execute the query generated after giving repair.
Now we have to go to the Studio → Meetings Module → Subpanels → Members module.
We can see the newly created field in the hidden layout, just drag and drop the field from the hidden section to the default layout section and Save & Deploy the field to the layout.

Here we go we can see the field in the members subpanel under the meetings module, but we are not yet done. We have to change the label of this field in the subpanels file.

Just change the field the Label in the below array.

array (
          'name' => 'meeting_status',
          'label' => 'Meeting Status',
          'enabled' => true,
          'default' => true,

Once this is done, we have to perform the Quick Repair and Rebuild. We are all set, now we are ready to use the relationship field and track member’s meeting status for a particular meeting.