Auto Populating the related module’s field data in the Current Module



We often have a requirement to populate the fields data of the related module on change of the related field in the current module. Let us take an example here. We have a parent-child relationship between the Accounts and Contacts module (one too many relationships). By default in SugarCRM when we are creating the Contact record, it auto-populates the address of the Account to the Contact record. Similarly we may come across the need to populate the other field’s data from Account to Contact record.

Let us take an example here.

If we want to populate the data to the Office Phone field in the Contacts module the same as the office phone in the Accounts module. This is quite simple by using the populate_list which triggers the logic whenever the account is changed in the Contact or linked to it.

Step – 1

Create the file in the below path and add this code../custom/Extension/modules/Contacts/Ext/Vardefs/<filename.php>
$dictionary[‘Contact’][‘fields’][‘account_name‘][‘populate_list’][ ‘phone_work’] = ‘phone_office’;
Let us understand a bit more about the parameters used in this file.

account_name refers to the relationship name of the Contacts and Accounts.
phone_work is the field name of the Office Phone field in the Contacts module.
phone_office is the field name of the Office Phone field in the Accounts module.
This code can be applied for any type of the field in any module. Make sure we are using the correct relationship names and field names when we are adding the code in the Vardefs.

Step – 2

Make sure you have proper permissions for all your file structure in the Sugar Root Directory. Now we have to perform the Quick Repair and Rebuild by navigating to the admin section in the SugarCRM instance. 

That’s all we are done. Now we can see the Office Phone field data populating from the Account when it is linked in the Contact Record.