Custom subpanel and getting record id

Hi all,

So followed steps here: http://urdhva-tech.blogspot.com/2013/02/add-custom-subpanel-in-accounts-module.html

And I got this working on my local dev build, but when I moved to my production install the $this->_focus->id doesn’t seem to be passing into my custom functions params. If I hard code an id the rest of the code works fine. Anyone know of something in server builds or system settings that may change the behaviour of retrieving that id variable and passing on?

I’m currently try to add a customised view of contacts owned by an employee in a subpanel on the employee’s detail page:

custom\Extension\modules\Employees\Ext\Layoutdefs\custom_subpanel.php:

$layout_defs['Employees']['subpanel_setup']['employee_contacts'] =
    array('order' => 49,
        'module' => 'Contacts',
        'subpanel_name' => 'ForEmployees',
        'get_subpanel_data' => 'function:get_employee_contacts',
        'generate_select' => true,
        'title_key' => 'LBL_EMPLOYEE_CONTACTS',
        'top_buttons' => array(),
        'function_parameters' => array(
            'import_function_file' => 'custom/modules/Employees/customContactsSubpanel.php',
            'user_id' => $this->_focus->id, // <--  this is blank, if I put a real id here, all else works
            'return_as_array' => 'true'
        ),
);

and
custom\modules\Employees\customContactsSubpanel.php:

function get_employee_contacts($params) {
	    $args = func_get_args();

	    $userId = $args[0]['user_id'];
	    $return_array['select'] = " SELECT contacts.*,c2.*, a2.*";
	    $return_array['from'] = " FROM contacts ";
	    $return_array['where'] = " WHERE contacts.deleted = '0' AND contacts.assigned_user_id = '" . $userId . "'";
	    $return_array['join'] = " INNER JOIN contacts_cstm c2 ON contacts.id = c2.id_c "; 
	    $return_array['join'] .= " INNER JOIN accounts_contacts ac ON ac.contact_id = contacts.id ";
  		$return_array['join'] .= " INNER JOIN accounts_cstm a2 ON a2.id_c = ac.account_id ";

	    $return_array['join_tables'] = '';
	    return $return_array;
	}

As I say, works on one, not on other, both windows though one is server one is windows 10. Both version 7.10 and working from same database backup.

Any thoughts greatly appreciated
Thanks
David

Well I seem to have solved this with a bean reference rather than grabbing the mythical $this->_focus_id I found in most tutorials

global $app;
$controller = $app->controller;
$bean = $controller->bean;
$userId = $bean->id; // <-- this was $args[0]['user_id'];

Great I’ve got this going but do wonder why this stuff feels so obscure and undocumented. Surely getting a subpanel of contacts an employee owns in a subpanel would be suitecrm 101 ?

1 Like