Flex-related subpanel

I have a custom module that contains a flex-related field and I wanted to add a subpanel to some other modules. I couldn’t see any way to do it so I did the following, which seems to work.

First, I created a file that contains a function to generate an SQL query:


if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');

function getFlexRecords($params) {
    $parentBean = $GLOBALS['app']->controller->bean;
    $flexBean = BeanFactory::getBean($params['module']);
    $query = "SELECT $flexBean->table_name.*
                FROM $flexBean->table_name
               WHERE $flexBean->table_name.deleted=0
                 AND $flexBean->table_name.parent_type = '$parentBean->module_name'
                 AND $flexBean->table_name.parent_id = '$parentBean->id'";
    return $query;

I put that in custom/Extension/application/Ext/GetFlexRecords.php, since this function will be used any time I want to add a subpanel.

Then, for each module that I want the subpanel to appear, I create a subpanel definition. For example, adding the subpanel to the Accounts detail view means creating a file in custom/Extension/modules/Accounts/Ext/Layoutdefs, e.g.


$layout_defs["Accounts"]["subpanel_setup"]["<PANEL NAME>"] = array (
  'order' => 100,
  'module' => '<MODULE NAME>',
  'subpanel_name' => 'default',
  'sort_order' => 'asc',
  'sort_by' => 'id',
  'title_key' => '<PANEL TITLE>',
  'get_subpanel_data' => 'function:getFlexRecords',
  'function_parameters' => array('import_function_file' => 'custom/Extension/application/Ext/GetFlexRecords.php', 'module' => '<MODULE NAME>),

where is the name you give to the panel and is the name of the the custom object.

Finally I create a language file to hold the subpanel title in custom/Extension/modules/Accounts/Ext/Language, e.g.:

$mod_strings['<PANEL TITLE>'] = '...';

Run a quick repair, and the subpanel should appear.

Assuming I haven’t missed anything, I hope this helps other people




Can you provide suitecrm.log or apache error.log entry if anything is caught when navigating to a record inside ‘Accounts’.

That would help debugging this issue.

I wasn’t reporting a bug. I was sharing a method I had found that seemed to do what I wanted


Sorry seems i misread the last part. :slight_smile:

Hi carbar,

I used your solution for 2 sub-panels, but it does not work, it always show 2 sub-panels of 1 module

Please help me.

Thanks Carl, it works great!! You save my life


Interesting approach

I too had an issue with Subpanels for Flex Relate fields and found out that:

  • A Flex Relate field is still a Relate field (with choices) so by default will NOT create a relationship and therefore will not create matching subpanels in the related modules
  • If you create a Flex Relate field using Studio, the field definitions go into the _cstm database table for the module, not the core database table for the module.
  • Relate (or Flex Relate) fields defined in the _cstm module require an extra level of sql query (via joins) and this can interfere with (easily) creating a subpanel to match the Flex Relate setup.
  • Use vardefs to create your Flex Relate fields and the field definitions will go into the core database table for the module, making it easier to then use the parent_id and parent_name to match up a subpanel in the related module.
  • Modules can only have one Flex Relate defined and can only have one parent_id and parent_name set; if the module into which you are trying to add a Flex Relate field already has a Flex Relate field or parent_id/parent_name set of fields defined, then adjust your vardefs accordingly


1 Like