Custom Subpanels

Hi all,

I’m trying to split the history panel into two separate sub-panels, one for calls and one for emails. I’m testing this out using the contacts module. So far what I’ve done is I’ve edited //modules/Contacts/metadata/subpaneldefs.php and added the following inside the subpanel_setup array:


'calls' => array(
  'order' => 11,
  'module' => 'Calls',
  'sort_order' => 'desc',
  'sort_by' => 'date_entered',
  'subpanel_name' => 'default',
  'get_subpanel_data' => 'calls',
  'title_key' => 'CUSTOM CALLS',
),

'emails' => array(
  'order' => 12,
  'module' => 'Emails',
  'sort_order' => 'desc',
  'sort_by' => 'date_entered',
  'subpanel_name' => 'ForHistory',
  'title_key' => 'CUSTOM EMAILS',
  'type' => 'collection',
  'collection_list' => array(
    'emails' => array(
      'module' => 'Emails',
      'subpanel_name' => 'ForHistory',
      'get_subpanel_data' => 'emails',
    ),
    'linkedemails' => array(
      'module' => 'Emails',
      'subpanel_name' => 'ForUnlinkedEmailHistory',
      'get_subpanel_data' => 'function:get_unlinked_email_query',
      'generate_select' => true,
      'function_parameters' => array('return_as_array' => 'true'),
    ),
  ),
),

However now what I want to do is for the emails subpanel, display who sent the email and who received the email. Does anyone know how to do this?

Thanks

This tutorial might help you:

https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/19222-subpanels-cases#66668

Maybe it’s easier to try and get it working from a simple example, with a single module. The History and Activities subpanels are special in SuiteCRM, they involve information from several modules.

Another thing that might work (I’ve never tried it) is creating a new simple subpanel from Studio, for Emails. You might not even need code.

I’ve tried the tutorial and it works for simple cases, but anything more complex it just seems to not want to work (I’ve probably done something wrong).

So far what I’ve done is in suitecrm/custom/Extension/modules/Contacts/Ext/Layoutdefs/Calls.php


<?php
$layout_defs["Contacts"]["subpanel_setup"]['calls'] = array(
    'order' => 10,
    'module' => 'Calls',
    'sort_order' => 'desc',
    'sort_by' => 'date_entered',
    'subpanel_name' => 'default',
    'get_subpanel_data' => 'function:getRelatedCallsQueryData',
    'function_parameters' => array(
      'import_function_file' => 'custom/modules/Contacts/GetCallsSubpanelData.php',
      'link' => 'calls'
    ),
    'add_subpanel_data' => 'call_id',
    'title_key' => 'LBL_CALLS_SUBPANEL_TITLE',
);

in suitecrm/custom/modules/Contacts/GetCallsSubpanelData.php


<?php
require_once 'custom/modules/Contacts/BuildCallsSubpanelQueryService.php';

function getRelatedCallsQueryData($param) {
  $service = new BuildCallsSubpanelQueryService();
  return $service->buildQuery($param);
}

in suitecrm/custom/modules/Contacts/BuildCallsSubpanelQueryService.php


<?php
class BuildCallsSubpanelQueryService {
  public function __construct()
  {}

  public function buildQuery($param) {
    global $app;
    $controller = $app->controller;
    $bean = $controller->bean;
    $query = "
      SELECT *
      FROM calls
      LEFT JOIN calls_contacts ON calls.id = calls_contacts.call_id
      LEFT JOIN calls_cstm ON calls.id = calls_cstm.id_c
      WHERE calls.deleted = 0 AND calls_contacts.contact_id = '$bean->id'
    ";
    return $query;
  }

The first issue I’ve come across is if I go to click on a call name to take me to the detail view of that call, I get the following error message: “Error retrieving record. This record may be deleted or you may not be authorized to view it.” The suitecrm.log wasn’t that helpful, it just repeated the error message:

The second issue I came across is if I add a custom column to the subpanel in the studio editor, the data for that column isn’t populated. I joined on the custom table (calls_cstm) in the SQL query, I’m not sure if there’s more I need to do.

I found out that if I remove the joins and simplify the SQL query to “SELECT * FROM calls” then I no longer get the error message mentioned above. However now I have no way to filter only for calls associated with the contact…

OK so the first error was because in the SQL query when I did the join, both the calls table and the calls_contacts table had a column called ‘id’. I guess this caused a conflict?

The second issue was because I had two fields with the same name, and I was using the wrong one which had no data associated with it, hence nothing appearing.

Try to get your Query right in phpMyAdmin first, when you know it’s working then move it into PHP code.

I suggest dropping the LEFT JOIN to calls_cstm since you’re not using any field from that table.

The repeated “id” field is not a problem if you always prefix the field with the table name (calls.id, etc)

I think I understand your issue. The problem is not on the Query. I’m having the same issue. I created my query on phpMyAdmin and got the desired results. The problem is when calling the query on the subpanel. When checking the logs I found that the system will add an extra left JOIN to the module_cstm table to obtain all custom and some extra fields. So, even when your query works the system will modify it and will fail.

I tried to use WHERE statement as recommended on another topic but it still doesn’t work.

Don’t know what the real solution is.