SugarCRM Custom filter to a Relate/Relationship field on Auto Popup List/Keypress

SugarCRM Custom Filter in Contacts Module

SugarCRM Custom Filter in Contacts Module

This article explains how to implement SugarCRM Custom Filter and why that’s required.

Business Need for SugarCRM Custom Filter.

SugarCRM contains huge data about the customer and related records.Many records are not required in day to day operations in SugarCRM. This records before problematic in creating and filtering new records and managing new clients in SugarCRM databases.
Since SugarCRM Database is required through out the life cycle of organization it’s must to keep the records and ensure that they don’t become a hurdle in managing the day to day records in the CRM System.

The best way to handle this is to create SugarCRM Custom Filter so that when the user opens the CRM and try to find out required records his search is limited to active records.

How SugarCRM Custom Filter

When we press a key in Relate field an ajax call is made through quicksearch.js

Consider an Example

“In Contact Module we have a relate field of accounts, we want to display only account other than type “Others”. You can have any condition over here like you can display accounts with type “Active”.

Considering only Accounts Not having status Other - SugarCRM

Now when user starts typing account name , quicksearch.js makes an ajax call to Home module. Request sends the data as shown in the below code box. Here we have started typing the letter “S”.

The request is sent to action quicksearchQuery and Module is “Home”

“{“form”:”EditView”, “method”:”query”, “modules”:[“Accounts”], “group”:”or”,
“Order”:”name”, “limit”:”30″, “no_match_text”:”No Match”}”,

The action “quicksearchQuery” calls the file “QuickSearch.php” (modules\Home\QuickSearch.php), and as you see in the above data , the module is passed as “Accounts”.

As per the standard coding practice, we create file QuickSearch.php in (\custom\modules\Home\QuickSearch.php).

Copy to code of file (\modules\Home\QuickSearch.php) to file (\custom\modules\Home\QuickSearch.php) .

Add following code in the file “custom/modules/Home/QuickSearch.php”

Declare a new Constant in the Class

/*——-New constant——-*/ const CONDITION_NOT_EQUAL = ‘not_equal’; /*——-New constant——-*/

In the “query”, function add the following line  before this statement


if (in_array(“Accounts”, $args[‘modules’]))


$args[‘conditions’][1] = array(

‘name’ => ‘accounts.account_type’,

‘op’ => ‘not_equal’,

‘end’ => ‘%’,

‘value’ => ‘Analyst’


$args[‘group’] = ‘AND’;



$args = $this->prepareArguments($args);        // this already exist in your code

In the function constructWhere() ad the following line of code in switch case

/*——–new case————*/


if ($condition[‘value’]) {



sprintf(“(%s != ‘%s’)”, $db->getValidDBName($condition[‘name’]),

$db->quote($condition[‘value’])) );



/*——–new case————*/

For more details and Implementation please contact us on here

Facebook Comments
  • Howdy, you are absolutely correct. I frequently read your site content carefully. I am likewise curious about towelroot apk, you might discuss that sometimes. Have a nice day!

  • Great beat ! I wish to apprentice while you amend your web site, how can i subscribe for a blog website? The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear concept

Leave a Reply

Show Buttons
Hide Buttons
Social Share Buttons and Icons powered by Ultimatelysocial