👋🏾 Looking to join our SuiteCRM Community Working Group? 💌 Open invitation throughout January. Check out all the details here 👈

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:


<?php

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.


<?php

$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.:


<?php
$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

Regards,

Carl

1 Like

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

C

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.