Custom subpanels

I am trying to generate my own subpanel following this instructions:

[i]First off, there’s the entry in the subpaneldefs, which has specific parts it in called out in the comments to indicate that we’ll be using a custom function to get the data we need.


$layout_defs['<<module name of parent module>>']['subpanel_setup']['<<subpanel name>>'] = array(
    // numeric order position of subpanel by default ( lowest number comes first )
    'order' => 10,
    'sort_by' => '<<default sort field>>',
    'sort_order' => '<<default sort order>>',
    'title_key' => '<<LBL_SUBPANEL_TITLE>>',
    'subpanel_name' => 'default',
    'module' => '<<module name of subpanel module>>',
    // Specify the custom function to call
    'get_subpanel_data' => 'function:getSubpanelQueryParts', 
    // Set to true to indicate we are building a custom SQL query
    'generate_select' => true,             
    'function_parameters' => array(
        // File where the above function is defined at
        'import_function_file' => 'custom/application/Ext/Utils/custom_utils.ext.php', 

Now comes the function itself, which thanks to the Ext Framework can be dropped in any .php file in the custom/Extension/application/Ext/Utils/ directory. Note the one thing you’ll want to do is get a reference to the current $bean object, which is easy to access thru the global scope as noted in the example below.


function getSubpanelQueryParts($params)
    $bean = $GLOBALS['app']->controller->bean;
    $return_array['select']='SELECT table1.field1, table1.field2, table2.field3 ';
    $return_array['from']='FROM table1 ';
    $return_array['where']=" WHERE table1.parent_id = '$bean->id' 
        AND field1.parent_type = 'Leads' AND NOT IN ( SELECT field1 FROM tableX ) ";
    $return_array['join'] = " LEFT JOIN table2 ON table1.field1 = table2.field1";
    $return_array['join_tables'][0] = '';
    return $return_array;

If you are on a version of Sugar prior to 6.3, you will need to drop the function in the custom/include/custom_utils.php file and change the above file reference to this file location as well.

With a Quick Rebuild and Repair, you’ll be up and going with your custom query.


And it works ! However is literally showing me all columns from table1 instead of the QUERY that I am trying to execute.

Any advise ?