SuiteCRM: Creating custom filter by related module’s field in list view page.

Kristian Cabading
Sep 7, 2018 · 3 min read

SuiteCRM filter in the list view only allows you to filter data based on the current module fields which can be customized in the Studio->{module name}->Filter. Then you can add the fields that will become available in the Quick or Advanced Filter.

List View Default Filter
Customizing the filter in Studio

I find very limiting especially when your module contains multiple relationships with other modules and the only way to make this available is via code. Below are the steps on how to do this:

  1. The first thing to do is to create the filter field (which doesn’t need to be in our database by the way since we are going to create a custom query with it) in the Filter view of our module. In your SuiteCRM directory, copy the searchdefs.php of your module located in modules/{modulename}/metadata/searchdefs.php and create a new copy to custom/modules/{modulename}/metadata/searchdefs.php. Insert a new item either in the basic or advanced_search key and add your new field just like below for the user_vendor_address and user_vendor_skillsets.

You should be able to see the new field after doing a Quick Repair/Rebuild in the admin.

2. Next thing to do is to create the file SearchFields.php in the custom/modules/{modulename}/metadata/SearchFields.php. There’s no need to copy the content of the main file located in the modules/{modulename}/metadata/SearchFields.php as we are just going to add new item in the searchFields metadata.(See below for example)

What you need to focus in the screenshot above is that we just added a new item in the $searchFields[‘mer_project_positions’] with a new key same as the one we set up earlier in our searchdefs.php. The new array contains query_type, operator and the subquery key that contains our custom query that matches a result based on a related module field in my case the addresses field on the user's table. The {0} variable in the query btw will be the value of the new filter field. Running Quick Repair and Rebuild in the admin should make the new filter to work and matches your result based on a related module’s field.

Full Stack Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade