HOWTO: Add custom fields into the global search

Matthew Marum —  April 29, 2011 — 23 Comments

As posted a few weeks back on this blog, we’ve added support from the UI to add custom modules into the global search in Sugar 6.2. But one other problem people have seen, as posted in this forums post, is that if you add custom fields to a module those are not able to be added to the global search thru the UI. But there is a way to do this thru some custom coding, as we’ll see here below.

The key to making this happen is to set the ‘unified_search’ parameter for the field. To do this, add new file under the custom/Extension/modules/YOUR_MODULE/Ext/Vardefs/customGlobalSearchFields.php directory with the following contents:

Then, you need to add a search definition for the file, which you can specify in the custom/modules/YOUR_MODULE/metadata/SearchFields.php file as shown below

Then do a quick rebuild and repair, and the field should now be available to be searched thru the global search.

Matthew Marum


Matt is the Director of Developer Advocacy for SugarCRM. Previously he was an Engineer on Sugar 7 and a Solutions Architect for the OEM program. He is also an avid trail runner, Boston Marathon qualifier and a karaoke aficionado.

23 responses to HOWTO: Add custom fields into the global search


    Anyway to get results to show up in the search preview window as well? This only works if I go to Full Form.


      I seeing it appear in both the search popup screen, as well as the full screen form. Which version of Sugar are you using?


        I was using 6.1.1 and had applied a similar workaround to add a custom field to global search that was in the accounts module. I’ll get a 6.2 box setup and test later. Thanks.


    One thing to note here is that for the SearchFields.php file, the ‘YOUR_MODULE’ value is the plural form.  I looked at the out of the box default SearchFields.php files and they use the plural form.  So for example, with the Accounts module you’d use “Accounts” for SearchFields.php, but “Account” for the vardef customization.


    This field not work in 6.3.0 version of sugarCRM


       It does work in 6.4.4. Be sure to make sure you are putting the right module name in the YOUR_MODULE piece above, just as the commenter above mentions.


    It’s not working, I try it in project:

    File ‘D:wwwsugarcrmcustomExtensionmodulesProjectExtVardefscustomGlobalSearchFields.php’  as that line :
    $dictionary[‘Project’][‘fields’][‘no_reference_projet_c’][‘unified_search’] = true;

    And file ‘D:wwwsugarcrmcustommodulesProjectmetadataSearchFields.php’ as that line at the begining :
    $searchFields[‘Projects’][‘no_reference_projet_c’] = array( ‘query_type’=>’default’);

    and I tried
    $searchFields[‘Project’][‘no_reference_projet_c’] = array( ‘query_type’=>’default’); too


    Has this been verified to work on version 6.5.x ?


    I tried in 6.4.4 CE Edition and it’s not searching.


    Confirmed working in 6.5.14. Thanks to Fred for the correction on module naming!


    Confirmed working in 6.5.14. Thanks to Fred for the information on module naming.


    This does not seem to work in v7.x


    I had to remove /cache/modules/unified_search_modules.php additionally to get it working. After removing it will be generated again after searching.


    i have added new field named converted with default value is 0. i want to add this where clause in global search when any first name or last name searched it should add where converted = 0. what should i do?
    i have added subquery but it did not result correctly

    ‘first_name’ => array(
    ‘query_type’ => ‘default’,
    ‘operator’ => ‘subquery’,
    ‘subquery’ => array(
    ‘SELECT id FROM leads WHERE leads.converted = 0 AND leads.first_name LIKE ‘,
    ‘db_field’ => array(‘first_name’),
    ‘last_name’ => array(
    ‘query_type’ => ‘default’,
    ‘operator’ => ‘subquery’,
    ‘subquery’ => array(
    ‘SELECT id FROM leads WHERE leads.converted = 0 AND leads.last_name LIKE ‘,
    ‘db_field’ => array(‘last_name’),
    ‘search_name’ => array(
    ‘query_type’ => ‘default’,
    ‘operator’ => ‘subquery’,
    ‘subquery’ => array(
    ‘SELECT first_name FROM leads WHERE converted = 0 AND first_name LIKE’,
    ‘SELECT last_name FROM leads WHERE converted = 0 AND last_name LIKE’,
    ‘OR’ => true
    ‘db_field’ => array(0 => ‘first_name’, 1 => ‘last_name’),
    ‘force_unifiedsearch’ => true

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