Show Activities/History etc. of Related Module in Primary Module

I’m looking for a way to show Activities/History information from a related modules within the Activities/History of the primary module. I’m currently working with a database of Accounts and within an Account I create Opportunities. Within an Opportunity I create activities (tasks) specific to that Opportunity. General activities related to an Account are created at the Account level.

When I’m at the Account level I want to be able to also see the activities created for the Opportunities that belong to the Account and indicate with a field to which Opportunity the activity belongs (or leave empty if it is a general activity created at the Account level).

I’ve looked into creating Related fields within the activity but this doesn’t seem to show the activity in the Primary Module activity list and is also not ideal as there’s an additional field to be set when creating an activity.

Is there a better solution to get this done? I assume I have to change the SQL query that selects all activities but I’m not entirely sure where this can be done?

1 Like

Not entirely sure this will work… but you could maybe create custom ‘ForActivities.php’ and ‘ForHistory.php’ files in /custom/modules/Opportunities/metadata/subpanels/ directory (create the directory if it doesn’t exist). From there, you can include some custom php to limit it to the Accounts module and a custom sql query to limit it to only the current account record. I haven’t looked too closely at the specifics of how you’d do it, but here is some custom ForActivities code I have used previously:


<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

$subpanel_layout = array(

	// custom query here (make sure to reference the table name, i.e. tasks.status or tasks_cstm. for custom fields)
	'where' => "(meetings.status NOT IN ('Held', 'Not Held', 'Cancelled', 'held_no_hire', 'held_no_options', 'Existing', 'rescheduled'))",
	
	// columns for the subpanel
	'list_fields' => array(
		'object_image'=>array(
			'vname' => 'LBL_OBJECT_IMAGE',
			'widget_class' => 'SubPanelIcon',
 		 	'width' => '2%',
			'image2'=>'__VARIABLE',
 		 	'image2_ext_url_field'=>'displayed_url',
		),
		'name'=>array(
			 'vname' => 'LBL_LIST_SUBJECT',
			 'widget_class' => 'SubPanelDetailViewLink',
			 'width' => '42%',
		),
		'status'=>array(
			 'widget_class' => 'SubPanelActivitiesStatusField',
			 'vname' => 'LBL_LIST_STATUS',
			 'width' => '15%',
		),
		'contact_name'=>array(
			 'widget_class' => 'SubPanelDetailViewLink',
			 'target_record_key' => 'contact_id',
			 'target_module' => 'Contacts',
			 'module' => 'Contacts',
			 'vname' => 'LBL_LIST_CONTACT',
			 'width' => '11%',
			 'sortable'=>false,
		),
		'contact_id'=>array(
			'usage'=>'query_only',
	
		),
		'contact_name_owner'=>array(
			'usage'=>'query_only',
			'force_exists'=>true
		),	
		'contact_name_mod'=>array(
			'usage'=>'query_only',
			'force_exists'=>true
		),		
		'date_start'=>array(
			 'vname' => 'LBL_LIST_DUE_DATE',
			 'width' => '10%',
		),
		'assigned_user_name' => array (
			'name' => 'assigned_user_name',
			'vname' => 'LBL_LIST_ASSIGNED_TO_NAME',
			'widget_class' => 'SubPanelDetailViewLink',
		 	'target_record_key' => 'assigned_user_id',
			'target_module' => 'Employees',
			'width' => '10%',		
		),
		'edit_button'=>array(
			'vname' => 'LBL_EDIT_BUTTON',
			 'widget_class' => 'SubPanelEditButton',
			 'width' => '2%',
		),
		'close_button'=>array(
			'widget_class' => 'SubPanelCloseButton',
			'vname' => 'LBL_LIST_CLOSE',
			'sortable'=>false,
			'width' => '6%',
		),
		'remove_button'=>array(
			'vname' => 'LBL_REMOVE',
			 'widget_class' => 'SubPanelRemoveButton',
			 'width' => '2%',
		),
		'time_start'=>array(
			'usage'=>'query_only',
	
		),	
		'recurring_source'=>array(
			'usage'=>'query_only',	
		),
	),
);		

And here’s ForHistory:


<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

$subpanel_layout = array(

	'where' => "(meetings.status IN ('Held', 'Not Held', 'Cancelled', 'held_no_hire', 'held_no_options', 'Existing', 'rescheduled'))",

	'list_fields' => array(
		'object_image'=>array(
			'vname' => 'LBL_OBJECT_IMAGE',
			'widget_class' => 'SubPanelIcon',
 		 	'width' => '2%',
 		 	'image2'=>'attachment',
 		 	'image2_url_field'=>'file_url'
		),
		'name'=>array(
			 'vname' => 'LBL_LIST_SUBJECT',
			 'widget_class' => 'SubPanelDetailViewLink',
			 'width' => '30%',
		),
		'status'=>array(
			 'widget_class' => 'SubPanelActivitiesStatusField',
			 'vname' => 'LBL_LIST_STATUS',
			 'width' => '15%',
		),
		'reply_to_status' => array(
			 'usage'				=> 'query_only',
             'force_exists'			=> true,
			 'force_default'		=> 0,
		),
		'contact_name'=>array(
			 'widget_class'			=> 'SubPanelDetailViewLink',
			 'target_record_key'	=> 'contact_id',
			 'target_module'		=> 'Contacts',
			 'module'				=> 'Contacts',
			 'vname'				=> 'LBL_LIST_CONTACT',
			 'width'				=> '11%',
			 'sortable'=>false,
		),
		'contact_id'=>array(
			'usage'=>'query_only',

		),
		'contact_name_owner'=>array(
			'usage'=>'query_only',
			'force_exists'=>true
		),
		'contact_name_mod'=>array(
			'usage'=>'query_only',
			'force_exists'=>true
		),
		'parent_id'=>array(
            'usage'=>'query_only',
			'force_exists'=>true
        ),
		'parent_type'=>array(
            'usage'=>'query_only',
			'force_exists'=>true
        ),
		'date_modified'=>array(
			 'vname' => 'LBL_LIST_DATE_MODIFIED',
			 'width' => '10%',
		),
		'date_entered'=>array(
			'vname' => 'LBL_LIST_DATE_ENTERED',
			'width' => '10%',
		),
        'date_start'=>array(
            'vname' => 'LBL_LIST_DUE_DATE',
            'width' => '10%',
        ),
		'assigned_user_name' => array (
			'name' => 'assigned_user_name',
			'vname' => 'LBL_LIST_ASSIGNED_TO_NAME',
			'widget_class' => 'SubPanelDetailViewLink',
		 	'target_record_key' => 'assigned_user_id',
			'target_module' => 'Employees',
			'width' => '10%',			
		),
		'edit_button'=>array(
			'vname' => 'LBL_EDIT_BUTTON',
			 'widget_class' => 'SubPanelEditButton',
			 'width' => '2%',
		),
		'remove_button'=>array(
			'vname' => 'LBL_REMOVE',
			 'widget_class' => 'SubPanelRemoveButton',
			 'width' => '2%',
		),
		'filename'=>array(
			'usage'=>'query_only',
			'force_exists'=>true
		),
		'recurring_source'=>array(
			'usage'=>'query_only',	
		),
	),
);

Good luck!

1 Like