SugarCRM: Populating fields using a Relate field

sugarcrmdevelopers —  April 10, 2013

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:

$dictionary['<MODULE_NAME>']['fields']['<RELATE_FIELD>']['populate_list'] = array('name', 'id', '<FIELD_FROM_RELATED_MODULE>');
$dictionary['<MODULE_NAME>']['fields']['<RELATE_FIELD>']['populate_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

3. Run Quick Repair and Rebuild.

Reference:

http://developers.sugarcrm.com/wordpress/2011/08/31/howto-using-a-relate-field-to-populate-a-custom-field/