JasonDavis
JasonDavis

Reputation: 48933

Show related module records that have a matching email address in a SugarCRM SubPanel?

We have 2 modules in SugarCRM.

Module 1 = Built in Contacts module

Module 2 = Custom module called QMS module.

We would like to be able to create a new contact user record in the contacts module and then have a subpanel in that contacts module that would show all related qms module records that are related to the contact record based on them having the same matching email field.

So to clarify...In the contacts module there is a default email field.

In our custom qms module we also have another email field.

When you view a contact module record with the email field value of [email protected] then in a sub panel it should show any qms module records that also have a matching email field that have a value of [email protected]

This is not built in standard behavior in SugarCRM CE 6.xx. Does anyone know how we can achieve such functionality?

Upvotes: 4

Views: 1724

Answers (1)

paquino
paquino

Reputation: 464

To accomplish this you need to create a custom function to fetch the data for your subpanel.

When implementing the QMS subpanel in modules/parent_module/metadata/subpaneldefs.php

'qms' => array(
        'order' => 40,
        'module' => 'QMS',
        'sort_order' => 'desc',
        'sort_by' => 'date_closed',
        'get_subpanel_data' => 'function:get_qms_contacts_subpanel',
        ...
        ),

Instead of providing a link field for get_subpanel_data, we tell it to use a function. This will tell the QMS subpanel to fetch the related records using the get_qms_contacts_subpanel function

Then in custom/Extension/application/Ext/Utils/some_file_name.php

Construct a function that will be used to form the query for your records.

<?php

function get_qms_contacts_subpanel()
{
   return array(
        "select" => "select distinct qms.id",
        "from" => "from qms",
        "join" => "join contacts on contacts.qms_id = qmd.contact_id" /*Obviously not the actual query but you get the point*/
        "where" => "where qms.email = contacts.email" /*See above*/
    );
}

I hope this helps.

See modules/Accounts/metadata/subpaneldefs.php for an example See the how the Emails subpanel fetches the Emails.

Check include/utils.php for the function used in the Email subpanel for more info on how to construct your function.

Upvotes: 5

Related Questions