Cameron Kilgore
Cameron Kilgore

Reputation: 423

Creating an Advanced Search field capable of searching multiple module fields

I am currently encountering issues trying to build a custom search field (itself bound to an unused field on a Module) to search two Phone Number fields. The documentation covering modifications of a search field are really poor, but I have the following in place in the module's SearchFields.php

  'phone' => 
  array (
    'query_type' => 'default',
    'operator' => '=',
    'db_field' => 
    array (
      0 => 'home_phone_c',
      1 => 'work_phone_c',
    ),
  ),

The field itself returns no results, so am I missing something that would prevent this from working?

Upvotes: 1

Views: 729

Answers (2)

ConRockets
ConRockets

Reputation: 46

You need to designate the correct tables. Try the below code (or use the tables that you're searching):

 'phone' => 
  array (
    'query_type' => 'default',
    'operator' => '=',
    'db_field' => 
    array (
      0 => 'accounts_cstm.home_phone_c',
      1 => 'accounts_cstm.work_phone_c',
    ),
  ),

Upvotes: 0

Abdur Rehman
Abdur Rehman

Reputation: 3293

why not you use "sub-query" operator for this? See SearchFields.php inside metadata folder of Account module. You will see entry like following:

'email' => 
  array (
    'query_type' => 'default',
    'operator' => 'subquery',
    'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
    'db_field' => 
    array (
      0 => 'id',
    ),
    'vname' => 'LBL_ANY_EMAIL',
  ),

this will help you to understand the sugar logic of doing it.

Upvotes: 1

Related Questions