Follow the instructions bellow:
The first example is how to complete this task using the Sugar Quick Search:
In your FTP client, navigate to your /custom/Extensions/modules/{MODULE NAME}/vardefs
From here you can either create a new file, or edit an existing file. Look for a file name sugarfield_{name_of_your_field}.php thatās the best place to add new code and maintain organization
Open that up and add the following lines:
$dictionary[ā{YOUR MODULE NAME}ā][āfieldsā][ā{YOUR FIELD NAME}ā][āpopulate_listā] = array(āidā,ānameā,ā{NAME OF DB FIELD YOU WANT TO ADD}ā);
$dictionary[ā{YOUR MODULE NAME}ā][āfieldsā][ā{YOUR FIELD NAME}ā][āfield_listā] = array(āaccount_id_cā,āaccount_nameā,ā{THE ID OF YOUR FIELD ON THE EDITVIEW LAYOUT}ā);
Youāll want to replace anything contained in curly brackets with the specific information for your application. The populate_list is a list of the database field names that you are going to be pulling from the database. The field_list is the list of fields that you are going to be placing these values.
Once you have this in place, go to Admin/Repair/Quick Repair and this process will rebuild the vardefs file in /custom/modules/{MODULE NAME}/Ext/vardefs/vardefs.ext.php.
Thatās all there really is to it from a technology standpoint, you can add fields to the arrays to populate more than 1field as well.
The Popup is where things are a little bit more tricky, at least until you know what you need to do. Setting it up in the code is easy enough.
Open /custom/modules/{YOUR MODULE}/metadata/editviewdefs.php
Field your field definition in the file, our full example is included below:
array (
ānameā => āaccounts_hdsmi_nym_customer_service_nameā,
ādisplayParamsā => array (
āfield_to_name_arrayā => array(
āidā=>āaccounts_h66a5ccounts_idaā,
ānameā=>āaccounts_hdsmi_nym_customer_service_nameā,
āaccountnum_cā => āaccount_number_cā,
),
āadditionalFieldsā => array(
āaccountnum_cā => āaccount_number_cā,
),
),
),
),
This is really all the code you need to get this set up. In the field_to_name_array and additionalFields array the key is the database field and the value is the Sugar field you are going to be populating. Pretty straight forward.
This next part is very important regardless of whether itās working or not. Go into Studio and click on the module that corresponds to the relate field you are working with. (Account relate field requires you to open the Accounts Module). Go into your layouts and find the layout for your Popup List View. If itās already working, then the custom field thatās being populated is already in that list view. If itās not working, youāll want to add that custom field to the list view. This is very important if it is working, because if that custom field is removed from the layout, it will stop working.
Source: http://developer.sugarcrm.com/2011/08/31/howto-using-a-relate-field-to-populate-a-custom-field/
If what you need is only save the content of relate field and not show dinamicaly in EditView, you can create a before_save logic hook.
Regards,
Roberto Dugim
CBR Consultoria
(+55) 11 2227-2321
www.cbrconsultoria.com.br