SugarCRM Customization: A Step-by-Step Guide to create a Custom Field in the Relationship Table

SugarCRM Customization: A Step-by-Step Guide to create a Custom Field in the Relationship Table

This blog is intended for SugarCRM developers aiming to create a custom field in the subpanel from the relationship table. Let’s explore the significance of customization in SugarCRM. When certain requirements cannot be met through personalization or configuration within Sugar, code-level customization becomes essential. Such customizations may involve expanding the out-of-the-box functionality by extending the SugarCRM code or integrating SugarCRM with third-party applications using RestFul API services. The people who are new to SugarCRM first they should go through the end user guide, admin guide and then only they can learn the SugarCRM custom development because it requires some understanding about how the application works and what and all the default features are available and how the SugarCRM can be personalized and configured by using Sugar default developer tools.

Now let us understand what is the importance of this blog. 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 be associated with multiple contacts. So let us see an example how the role field in the subpanel plays a vital role here.

How does the Contacts Role Field under Opportunities play a significant role in SugarCRM?

  1. In SugarCRM, 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. 
SugarCRM Contacts Role in Opportunity Subpanel
  1. 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.

Creating Custom Subpanel Fields through Customisation for Many-to-Many Relationships in SugarCRM

This blog will guide you through creating a custom dropdown field in the Members subpanel under the Meetings Module. Imagine a scenario where there’s a Many-to-Many relationship between Meetings and Members – meaning multiple members can attend various meetings, and each meeting can have multiple attendees.

The ‘role’ field here serves as a useful indicator to mark whether a member attended a specific meeting or not. When we establish a Many-to-Many relationship between these modules, SugarCRM automatically generates metadata and relationship files in both modules’ vardefs.

However, since this field is part of a relationship, you can’t create it using tools like Studio or Module Builder. This has to be done through custom code development only. Adding small code snippets into specific files will help achieve this customization as mentioned in the below steps.

Step 1: Adding the Field in the Subpanel Module

To display the field in the subpanel, we need to add it to the metadata file. Follow these steps:

  1. Navigate to the file path: (./custom/metadata/meetings_psme_members_1MetaData.php).
  2. Inside this file, find the ‘fields’ array.
  3. Add the following code snippet within the ‘fields’ array.

Note: The path mentioned (./custom/metadata/{link_name}MetaData.php) might differ based on the relationship. Typically, it will follow a similar structure, adjusting the ‘link_name’ based on the relationship between modules.

Step 2: Adding the Field in the Relationship File

When establishing a Many-to-Many (M-M) relationship between modules like Meetings and Members, SugarCRM creates specific files in both module directories under Vardefs.

  1. To incorporate the ‘meeting_status’ field into this relationship, follow these steps:
    1. Locate the file at the path
      ./custom/Extension/modules/PSME_Members/Ext/Vardefs/meetings_psme_members_1_PSME_Members.php
    2. Add the provided code snippet to the end of the file:
  1. In this code, the ‘type’ parameter set as ‘enum’ indicates that ‘meeting_status’ will be a dropdown field. The ‘options’ attribute, set to ‘meeting_status_type_list’, specifies the list of options that will be available in this dropdown.
  2. This addition within the relationship file defines the ‘meeting_status’ field as a dropdown, providing a predefined set of choices within the relationship between Meetings and Members.

Step 3: Creating the Dropdown Field ‘Meeting Status’ in the Members Module

  1. To display the status of a member for a meeting, create a dropdown field named ‘Meeting Status’ in the Members module. Follow these steps.
    1. Create a file at the path: ./custom/Extension/modules/<PSME_Members>/Ext/Vardefs/<filename.php>
    2. Insert the following code into the new file created and save the file.
  1. Explanation of Parameters used in the above code are as follows.
    1. ‘type’ => ‘enum’ → Specifies the data type of the field as a dropdown (‘enum’).
    2. ‘link’ => ‘meetings_psme_members_1’ → Refers to the link name created during the relationship setup between modules.
    3. ‘options’ => ‘meeting_status_type_list’ → Indicates the name of the dropdown list containing options for the ‘meeting_status’ field.
    4. ‘PSME_Members’ module refers to the module name where this field is being added.
  2. This code addition creates a dropdown field named ‘Meeting Status’ within the Members module, enabling the display and selection of different meeting statuses for each member.

Step 4: Creating the Dropdown List ‘meeting_status_type_list’

  1. To create the dropdown list ‘meeting_status_type_list’ used for the ‘Meeting Status’ field, follow these steps.
    1. Navigate to the file path: ./custom/Extension/application/Ext/Language/<en_us.<filename>.php.
    2. Add the following code snippet into the file.
  1. This snippet of code defines the dropdown list ‘meeting_status_type_list’. Each key-value pair represents an option in the dropdow:  ‘Selected’, ‘Invited’, ‘Accepted’, ‘Rejected’, ‘Attended’, ‘Absent’ are the options available for the ‘Meeting Status’ dropdown field.
  2. By adding this code snippet to the specified language file, you create a list of selectable options for the ‘Meeting Status’ dropdown field in the Members module.

Step 5: Finalizing Changes and Updating Layout

  1. Perform Quick Repair and Rebuild.
    • After placing all the necessary files, access the Admin section within your Sugar instance.
    • Perform the Quick Repair and Rebuild action. Execute the query generated after the repair process concludes. This ensures that Sugar recognizes and applies the recent changes effectively.
  2. Adjust Layout via Studio by following the below steps.
    • Go to Studio and open the Meetings Module.
    • Navigate to Subpanels and locate the Members module.
    • In the ‘hidden layout’ section, find the newly created field.
    • Simply drag and drop this field from the hidden section to the ‘default layout’.
    • Save & Deploy the field to update the layout.
Studio is a developer tool for modifying the subpanel layouts in SugarCRM

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.

Step 6: Modifying the Field Label in the Subpanel File

To change the label of the field displayed in the Members subpanel under the Meetings Module, follow these steps

  1. Navigate to the file path as mentioned below (.custom\modules\PSME_Members\clients\base\views\subpanel-for-meetings-meetings_psme_members_1\subpanel-for-meetings-meetings_psme_members_1.php)
  2. Locate the array related to the ‘meeting_status’ field inside this file and Adjust the ‘label’ attribute in the array to change the field label as shown in the below.
  1. 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 members meeting status for a particular meeting.
  2. After performing all the steps as mentioned in this blog, you can see the Meeting Status field in Members Subpanel under the Meetings module as shown in the below screenshot.
Adding the fields in the Subpanels in the custom modules through studio

Conclusion

In summary, custom role-based fields in CRM subpanels make it easier to understand different roles and help in making better decisions. Doing database operations and programming for these changes demonstrates the CRM system’s ability to adjust and improve how data is handled, leading to smarter business methods. Bhea is the trusted SugarCRM partner with extensive experience since 2004, specializes in implementing and supporting CRM systems tailored specifically to meet diverse business needs. As a leading authority in SugarCRM, Contact Us for all your CRM/SugarCRM implementation and support requirements.