I answered a similar problem in another thread, but since this was the thread that got me started I thought I'd post my solution here too. Note, I haven't figured out how to add this to the Target List Contacts pop-up. Instead, the end-user is forced to find contacts using the Contacts Advanced Search and then use the features of the Power Prospecting module to add the contacts list to the desired Target List. Also, the workaround for the contacts list selection bug (Sugar bug #19107) was critical for me as well. Anyways here goes:
It took me quite a bit of trial and error, and endless hours stepping through the debugger, to figure out, but I found vardef settings that seem to work for searching Contacts using a custom field in the Accounts module. I created a new php file custom/Extentions/modules/Contacts/Ext/Vardefs/ContactsAccountSearch.php, but you could just directly put this directly in modules/Contacts/vardefs.php instead. Here's what I added:
Code:
$dictionary['Contact']['fields']['account_status_c'] = array (
'name' => 'account_status_c',
'rname' => 'account_status_c',
'id_name' => 'id_c',
'vname' => 'LBL_ACCOUNT_STATUS_C',
'join_name'=>'accounts_cstm',
'type' => 'relate',
'link' => 'accounts_cstm',
'table' => 'accounts_cstm',
'isnull' => 'true',
'module' => 'Accounts',
'dbType' => 'varchar',
'len' => '255',
'source' => 'non-db',
'unified_search' => false,
);
$dictionary['Contact']['fields']['accounts_cstm'] = array (
'name' => 'accounts_cstm',
'type' => 'link',
'relationship' => 'accounts_accounts_cstm',
'link_type' => 'one',
'source' => 'non-db',
'vname' => 'LBL_ACCOUNT_CSTM',
'duplicate_merge'=> 'disabled',
);
$dictionary['Contact']['relationships']['accounts_accounts_cstm'] = array (
'lhs_module' => 'accounts_cstm',
'lhs_table' => 'accounts_cstm',
'lhs_key' => 'id_c',
'rhs_module' => 'Accounts',
'rhs_table' => 'accounts',
'rhs_key' => 'id',
'relationship_type' => 'one-to-one',
);
I'm still trying to figure out how to make the search field additions completely upgrade safe (i.e. in a Extension file like above), but I just added the field to to the end of the 'advanced_search' declaration in custom/modules/Contacts/metadata/searchdefs.php :
Code:
'account_status_c' =>
array (
'name' => 'account_status_c',
'default_value' => '',
'type'=>'varchar', // to avoid having the regular Select button for the Accounts module popup appear
), The query building code in Sugar expects tables to have a deleted column. Rather than hack this code it seemed easier to just add a deleted field to the accounts_cstm table. From your favorite mysql client:
Code:
ALTER TABLE accounts_cstm ADD COLUMN deleted tinyint(1) DEFAULT 0;
Hope this helps someone else out!
Bookmarks