salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.27k stars 2.03k forks source link

Custom subpanels not loading data until the page is reloaded #10365

Open pablonr11 opened 4 months ago

pablonr11 commented 4 months ago

Issue

When you try to open a subpanel introduced using a custom layour def the subpanel first loads empty. Once you reload the page mantaining the subpanel opened the data loads correctly. The same occurs when you try to order the subpanel by some column.

Expected Behavior

When opening/ordering the subpanel the data should load the same way as the other subpanels in the CRM

Actual Behavior

Since the record is not retrieved on the bean you can't acceed the id in the _focus on the layout defs you can't run the custom query properly. This makes the subpanel load empty.

Possible Fix

In include/SubPanel/SubPanelViewer.php around line 86 changing

$bean = BeanFactory::getBean($module);

for

$bean = BeanFactory::getBean($module, $record);

This will retrieve the current record in the bean which will allow the custom subpanel layout_def to acceed the id in $this->_focus.

Steps to Reproduce

  1. Create a custom layout_def subpanel that loads data using a function and makes use of $this->_focus->id as a function parameter. For example
    $layout_defs['act_Empleados']['subpanel_setup']['act_empleados_act_vacaciones_empleados'] = array(
    'order' => 100,
    'module' => 'act_vacaciones_empleados',
    'subpanel_name' => 'default',
    'sort_by' => 'date_entered',
    'sort_order' => 'desc',
    'title_key' => 'LBL_ACT_EMPLEADOS_ACT_VACACIONES_EMPLEADOS',
    'get_subpanel_data' => 'function:getEmployeeHolidays',
    'add_subpanel_data' => 'act_vacaciones_empleados_id',
    'generate_select' => false,
    'top_buttons' => array(),
    'function_parameters' => array(
        'import_function_file' => 'custom/modules/act_vacaciones_empleados/subpanelFunctions.php',
        'employee_id' => $this->_focus->id,
        'return_as_array' => 'false'
    ),
    );

Context

I was implementing a custom subpanel that shows some employee holidays and I needed to show only the future holidays so i needed to filter the ones that already happened.

In most cases the default relationships that you can build with studio/module builder are enough. I think the times a custom subpanel is needed are low. I'll mark this as a medium issue.

Your Environment