AnsweredAssumed Answered

Auto populate custom fields on Opportunity using a Relate field

Question asked by mayank.chandan on Jul 12, 2014
I have two custom fields on opportunity, City and State. Whenever an Account (Through relate field) is mapped with an Opportunity (On Edit view). It should auto populate custom fields (State and City) of opportunity with Billing State & City from Accounts

These should work with Account selection through pop up and by typing (Quick Search) in the account Relate Field

Proposed Solution

Schema (Field names) -- Opportunity Module
account_id (Hidden )
account_name (Relate Field)
city_c (custom field)
state_c (custom field)

Schema (Field names) -- Accounts Module
id (id)
name (account name) 
billing_address_city (custom field)
billing_address_state (custom field)




// For quick search
Adding attributes of populate_list & field_list in custom/modules/Opportunities/Ext/Vardefs/vardef.php

<?php
$dictionary['Opportunity']['fields']['account_name']['populate_list'] = array('name', 'id', 'billing_address_city','billing_address_state');
$dictionary['Opportunity']['fields']['account_name']['field_list'] = array('account_name','account_id','city_c','state_c');

?>

// For Pop up

Modifying the display Params of a relate field in custom/modules/opportunities/metadata/editviewdefs.php

array (          0 => 'account_name',
          'displayParams' => 
          array (
             'field_to_name_array' => array (
            'id'=>'account_id',
             'name' => 'account_name',
             'billing_address_city'=>'city_c',
             'billing_address_state'=>'state_c',
             ),
           ),

Solution for quick search is working but not for pop up. Not sure what have I done  wrong over

I referred the below url to get these working

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


Any input on the above is highly appreciated.

Thanks
Mayank Chandan



















Outcomes