This will allow you to populate a field/fields when a value is selected in a relate field.
1. Go to <sugar>/custom/Extension/modules/<MODULE_NAME>/Ext/Vardefs/ and create a new file (ex. vardef.ext.php)
2. Add the following codes to the file: (This is for the quicksearch)
$dictionary['<MODULE_NAME>']['fields']['<RELATE_FIELD>']['populate_list'] = array('name', 'id', '<FIELD_FROM_RELATED_MODULE>'); $dictionary['<MODULE_NAME>']['fields']['<RELATE_FIELD>']['field_list'] = array('account_name', 'account_id_c', '<FIELD_TO_POPULATE>');
* In the example:
RELATE_FIELD is the Relate field id we want to use (in the example, we used the account_name)
FIELD_FROM_RELATED_MODULE is the db name of the field we want to get from related module
FIELD_TO_POPULATE is the field in current module that we want to populate with value from FIELD_FROM_RELATED_MODULE
account_id_c is the hidden field in a Relate Field where the id of the record selected is stored
* Note that the name should be the first item in the array because the auto complete of Relate field shows the result from the first item in the array
* This doesnt work when populating a relate field
3. Search the field declaration in custom/modules/<MODULE_NAME>/metadata/editviewdefs.php and add the code below (This is for the popup window)
(Example if you want to populate another relate field)
'displayParams' => array( 'field_to_name_array' => array( '<ID_FROM_RELATED_MODULE>' => '<ID_OF_RELATE_FIELD>', '<NAME_FROM_RELATED_MODULE>' => '<NAME_OF_RELATE_FIELD>', '<ID_OF_ANOTHER_RELATE_FIELD>' => <ID_OF_ANOTHER_RELATE_FIELD_TO_POPULATE> '<NAME_OF_ANOTHER_RELATE_FIELD>' => <NAME_OF_ANOTHER_RELATE_FIELD_TO_POPULATE> ), ),
* Dont forget to include the fields of the relate field we are using to populate another relate field
4. Run Quick Repair and Rebuild.