Adding records to History Subpanel?

So I’ve followed this: Add custom subpanel in Accounts module

I can write a Task subpanel and I can write a cutom function to get tasks that are both related to the Account or the Opportunity.

So now move on to get more complicated, to also add calls and meetings, I’m trying to follow the existing structure similare to how emails are added to Activities. I just can’t get it to work. Has anyone ever tried extending the activities and the history to include other related records?

Here’s what I have so far (again, if I follow the example I can make it work, just not as a collection list):

$layout_defs['Accounts']['subpanel_setup']['custom_activities'] = array(
    'order' => 55,
    'title_key' => 'LBL_CUSTOM_ACTIVITIES_SUBPANEL_TITLE',
    'type' => 'collection',
    'subpanel_name' => 'activities', // Using a generic 'activities' layout
    'module' => 'Activities',
    'header_definition_from_subpanel' => 'meetings',
    'collection_list' => array(
        'tasks' => array(
            'module' => 'Tasks',
            'subpanel_name' => 'ForActivities',
            'get_subpanel_data' => 'function:get_custom_related_tasks',
            'function_parameters' => array(
                'import_function_file' => 'custom/modules/Accounts/customActivitiesFunctions.php',// Path to your PHP file
				'account_id' => $this->_focus->id, // Passing current account ID dynamically
				'return_as_array' => 'true'
            ),
        ),
       
    )
);



and the function

function get_custom_related_tasks($params) {
     $accountId = $params['account_id']; 
    $GLOBALS['log']->fatal("Fetching tasks related to Account ID and its Opportunities: {$accountId}");

    $return_array = array();
    $return_array['select'] = "SELECT tasks.*";
    $return_array['from'] = "FROM tasks";
    $return_array['where'] = "WHERE tasks.deleted = 0 AND (tasks.parent_id = '{$accountId}' AND tasks.parent_type = 'Accounts' OR tasks.parent_id IN (
        SELECT opportunities.id 
        FROM opportunities 
        JOIN accounts_opportunities ON opportunities.id = accounts_opportunities.opportunity_id 
        WHERE accounts_opportunities.account_id = '{$accountId}' AND opportunities.deleted = 0 AND accounts_opportunities.deleted = 0
        ) AND tasks.parent_type = 'Opportunities')";
    
    $GLOBALS['log']->fatal('Constructed SQL for Task Fetch: ' . print_r($return_array, true));
    return $return_array;
}
1 Like