title: Cross module searches in SugarCRM
body: <p>I am trying to add support to search across modules in SugarCRM. More specially, I would like to add a filter in Contacts search to filter contacts whose account has certain description.</p>
  
  <p>I have consulted various posts such as the following:
  <a href="http://developers.sugarcrm.com/wordpress/2011/04/19/howto-add-a-search-field-that-searches-another-module/" rel="nofollow">http://developers.sugarcrm.com/wordpress/2011/04/19/howto-add-a-search-field-that-searches-another-module/</a></p>
  
  <p>However I still failed to accomplish what I need to do.</p>
  
  <p>I have made the following changes to searchdefs.php to add a new field "account_desc" to the advance search panel.</p>
  
  <pre><code>        'account_desc' =&gt; 
            array (
              'name' =&gt; 'account_desc',
              'label' =&gt; 'Acct desc',
              'type' =&gt; 'name',
              'default' =&gt; true,
              'width' =&gt; '10%',
            ),
  </code></pre>
  
  <p>Then, I added the query in SearchFields.php</p>
  
  <pre><code>    'account_desc'=&gt; array(
          'query_type'=&gt;'default', 
          'operator'=&gt;'subquery',
          'subquery'=&gt;'SELECT contact_id FROM Contacts JOIN accounts_contacts JOIN accounts ON (Contacts.id = contact_id AND accounts.id = account_id) WHERE accounts.description LIKE',
          'db_field' =&gt; array(
              'id',
          ),
  </code></pre>
  
  <p>The subquery will output list of contact id whose account has certain description. And then SugarCRM will just match the contact id against this list to get the final output.</p>
  
  <p>Unfortunately, it seems that I am still missing something. Can anyone tell me what is wrong?</p>
  
  <p>Thanks,</p>