In contact module I've add an relational field of account. Now I want that when I use the account field and select an account from the list, then the name , email , and phone number field of contact module will fill out with the name , email and phone of that account which will I select by using relational field of account. How can I do that please define the code and also directory where I have to add your define code to perfome this task.

I've tried a logic hook by searching over the internet, in my directory of custom/module/contacts/populated fields.php, here is the code but it didn't working at all.

`<?php
if (!defined('sugarEntry') || !sugarEntry) {
    die('Not a valid entry point.');
}
class PopulateFields
{
    function populate($bean, $event, $arguments)
    {
        // Check if the Account field has changed
        if ($bean->account_id != $bean->fetched_row['account_id']) {
            // Retrieve the selected Account's information
            $accountBean = BeanFactory::getBean('Accounts', $bean->account_id)     
            // Populate the fields with the Account's information
            if (!empty($accountBean)) {
                $bean->name = $accountBean->name;
                $bean->email1 = $accountBean->email1;
              $bean->phone_office = $accountBean->phone_mobile;
            }
        }
    }
}
`
1

There are 1 best solutions below

0
Mohammed Jhosawa On

If you want to fill out those information on Record View itself then you might need to write the custom logic at the front end (record.js)

Check Sugar Cookbook - https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.0/Cookbook

And, If you're okay that it should populate after you click on the save button on record view then (before_save) Logic hook would be the best approach.

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Architecture/Logic_Hooks/Module_Hooks/before_save/

Hope it helps!