Filtering Sugar SubPanels

Sugar doesn’t have a means of filtering subpanels built into it. This is a serious drawback if you have subpanels with a lot of data in them. However, it’s possible to create your own filter with a little work. I’ll explain my solution here.

First, here’s a screenshot of a notes subpanel for a client record on an installation of Sugar that I work on:

The company makes customer advice agents record a contact with every note in a client record, and as the list of notes grows it becomes important to be able to filter them by contact. To do this I create a selector with an onchange parameter that calls Sugar’s showSubPanel() javascript function.

I need to pass the id of the contact to filter by as a parameter in the request. showSubPanel() has a fourth parameter, layout_def_key.

Any value passed to that parameter causes “&layout_def_key=xyz” to be appended to the URL. You can inject any other parameters you like into the URL using this parameter.
In my case I pass the value “&contact_id=abc” which causes the URL to be formatted something like this:


Now, since I have a contact_id parameter in the request, I can add a where clause to my subpanel in custom/modules/Notes/metadata/subpanels/ForMyCustomModule.php like so:

To render the contact list I create a widget which is configured in the subpanel layout definitions as a button. It’s the first button in the above example, called SubPanelContactFilter.

The code for the widget is stored in include/generic/SugarWidgets/SugarWidgetSubPanelContactFilter.php and looks something like this:


Now, you can see in my code that I use javascript to set the value of the select to the chosen contact. This is because the showSubPanel() function, when inserting the newly fetched data into the subpanel, prevents any use of the “selected” attribute on a select option from working.

In order to make the javascript execute I also had to modify showSubPanel(), adding a line to cause the script to be executed, like so:

That completes the work needed to make a subpanel filter. Here’s the filtered result:

5 thoughts on “Filtering Sugar SubPanels

  1. item

    Thanks a lot.

  2. […] Sugar allows you to specify a where clause in a subpanel This is useful if you want to show only certain records in the subpanel, or to filter the subpanel results, as detailed in my blog entry Filtering Sugar Subpanels. […]

  3. KUDOS DUDE ……….. I am a Sr SugarCRM engineer and things is probably one my most all time favorite hacks. You rock.
    Hey contact me, if you like, it would be nice to be with true talent.

  4. David,
    My email is WHERE ARE YOU UPDATING showSubpanel()

    • David

      Hi Michael, I’m glad you like the hack and I hope you find it useful. You should find the showSubPanel() function in:

      IIRC this is minified somehow so you may need to clear caches after editing. Good luck 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">