Adding custom fields to the Activities or History subpanels

sugarcrmdevelopers —  October 29, 2012 — 18 Comments

I’ve seen a few questions around adding custom fields to those subpanels that pull together all your Call, Meeting, Task, Email, and Notes data into very easy to view containers…

The problem most developers find is that it’s not that simple to add new fields to them. Luckily, the drive and determination of our community came to the plate here, with forums poster Alkana digging into the code to find a nice solution to the problem. Let me detail it here.

First, we need to define the field that will be drawn from in the module that will have the field. For non-custom fields this is simple as you can just reference the field, but for custom fields it’s a bit more involved as shown in the code example ( to be added to the /custom/modules/<<Calls/Meetings/Tasks/Emails/Notes>>/metadata/subpanel/ForActivities.php or the /custom/modules/<<Calls/Meetings/Tasks/Emails/Notes>>/metadata/subpanel/ForHistory.php )

Note the interesting attributes here…

  • force_default, which allows you to add extra SQL in there to join out to the cstm table.
  • force_blank will escape the replacement of custom definition by the default field
  • force_exists will give you access to add custom default SQL string

You could also use this technique for joining to other tables here instead.

Next, we need to add a placeholder field for the other modules that don’t have this field. Add this segment to each of the other module’s ForActivities.php and ForHistory.php…

Big thanks to Alkana again for this great solution!

UPDATE: 25/01/2013 – As pointed out by Cédric Mourizard below, if this field you’ve added isn’t defined in the vardefs for the module, it won’t show up. So add this to a new /custom/Extension/modules/<modulename>/Ext/Vardefs/<you_custom_field_name>.php file…

Thanks Cedric for chiming in here!

18 responses to Adding custom fields to the Activities or History subpanels


    Even after doing this a few times, it’s very difficult to articulate and remember the multiple steps, I suppose because it touches so many different modules. This post was long needed and much appreciated. Thanks John and Alkana.


    For safe measure, I like to additionally include custom/modules/Emails/metadata/subpanels/ForUnlinkedEmailHistory.php in that list of files to modify.


    Thanks for sharing. It’s half-working for me, I get the new column in my subpanel, but with empty content 😦 even when the sql query does return some text. Maybe someone knows why.


      Could you share the files you modified?


        Inside my opportunities subpanel I’ve just added a new field like this:

        ‘my_field’ => array (
        ‘force_blank’ => true,
        ‘force_exists’ => true,
        ‘vname’ => ‘My Field’,
        ‘force_default’ => ‘(SELECT “example”) AS’,
        ‘width’ => ‘10%’,

        Just an example, of course, but should work as sql query is working (I’ve tested).
        Result query like this:

        SELECT , , (SELECT “example”) AS my_field ,(…)

        So, if field creates the column and query is workign, I really don’t know what’s wrong 😦

    Gireesh Dwivedi July 19, 2013 at 10:04 am

    Hi, I am getting mysql error:

    MySQL error 1242: Subquery returns more than 1 row

    This is field description that i am using in forHistry.php


    ‘force_blank’ => true,

    ‘force_exists’ => true,

    ‘vname’ => ‘My_Field’,

    ‘force_default’ => ‘(SELECT subject_task_c FROM calls_cstm,calls WHERE AS’,



    I am trying to do this same thing but I do not get the column header showing up… Added two fields, priority_note_checkbox_c and task_type_c… I get the column for one (priority) but no col header

    ‘priority_note_checkbox_c’ => array(
    ‘force_blank’ => true,
    ‘force_exists’ => true,
    ‘force_default’ => ‘(SELECT priority_note_checkbox_c FROM calls_cstm WHERE AS’,
    ‘task_type_c’ => array(
    ‘force_blank’ => true,
    ‘force_exists’ => true,
    ‘vname’ => ‘LBL_TASK_TYPE’,
    ‘force_default’ => ‘(SELECT task_type_c FROM calls_cstm WHERE AS’,

    I added them after Status, and I dutifully added the place holder fields to all the others () like this in same place after status…in the ForHistory and ForActivity and the ForUnlinkedEmailHistory php’s
    ‘priority_note_checkbox_c’ => array(
    ‘usage’ => ‘query_only’,
    ‘force_exists’ => true,
    ‘task_type_c’ => array(
    ‘usage’ => ‘query_only’,
    ‘force_exists’ => true,

    Is there some where else where the columns are defined for the history & activities panel on accounts?


    No worky. I think I may be making some incorrect assumptions.
    I have a custom field (prima_note_type_c) added to the Notes module that I want to show in the History subpanel.


    The above file didn’t exist and neither did the subpanel directory. I created both.
    So the complete contents of the file is as follows:

    $subpanel_layout[‘list_fields’][‘prima_note_type_c’] => array(
    ‘force_blank’ => true,
    ‘force_exists’ => true,
    ‘vname’ => ‘Note Type’,
    ‘force_default’ => ‘(SELECT prima_note_type_c FROM notes_cstm WHERE AS’,

    I created the subpanel directory and ForHistory.php files for the Calls, Meetings, Tasks, and Emails directories. For these, ForHistory.php contains only the following:

    $subpanel_layout[‘list_fields’][‘prima_note_type_c’] =>array(

    I did a rebuild and nothing happened. No new column in my subpanel. Am I missing anything?


    please fix the blog post example paths. I wasted a day and a 1/2 on this

    This is the fixed path example:

    In the original post, there was no ‘s’ at the end of subpanels, and it will not work if the folder name is subpanel.

    I made many minor changes in my own code trying to resolve this, so I don’t know if the rest of the provided code above is correct as is. OP Please test your example code before posting it to save everyone else a lot of time. 🙂

Trackbacks and Pingbacks:

  1. Add Custom date field to History Subpanle - March 20, 2013

    […] […]

  2. Add project name on the subpanel activities for a contact - December 20, 2013

    […] […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s