Reputation: 77
i'm using suite crm 7.7.5
when i create an opportunity and i choose an account from a relate field, i want a field (country) to be auto populated with the value of the country of the account chosen.
for this, i tried to add the code
$dictionary['Opportunity']['fields']['country_c']['populate_list']= array('id','name','country_c');
$dictionary['Opportunity']['fields']['country_c']['field_list'] = array('account_id_c','account_name','country_c');
in the file \custom\Extension\modules\Opportunities\Ext\Vardefs\sugarfield_country_c.php
knowing that country_c is the name of the column country in the table accounts and the second country_c is the id of the field country in the layout opportunity
but that doesn't work, could someone help me to figure out the reason?
PS : i've tried to follow this tutorial https://developer.sugarcrm.com/2011/08/31/howto-using-a-relate-field-to-populate-a-custom-field/
Upvotes: 1
Views: 3192
Reputation: 1508
Here is the extension on @Bozic solution.
If someone is trying to autopopulate related fields based on selection then here is the solution. (Those who are facing "No match for field: Account Name")
Scenario: I have Account Owner (relate to User module) field in Accounts module. And in Cases module I am fetching Account owner fields based on Account selection.
In /custom/modules/Cases/metadata/editviewdefs.php
0 => array(
'name'=>'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_name',
'assigned_user_name' => 'account_owner_case_c',
'assigned_user_id' => 'user_id2_c',
),
),
),
Note:
Upvotes: 1
Reputation: 46
Use field billing_account_country rather than country_c, and also use account_id with account_name. The name and the id have to coincide to the same table, I believe.
Upvotes: 0
Reputation: 157
You should go to custom/modules/{YOUR MODULE}/metadata/editviewdefs.php and edit editviewdefs.php file.
First you need to find array in which your relate field(account_name) is defined. It will look similar to this, maybe with some more parameters.
array (
'name' => 'account_name',
),
Now you need to map data from relate field(country_c) to new field(lets say populated_country_c). After editing your array will look something like this.
array (
'name' => 'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_id_c',
'name'=>'account_name',
'country_c' => 'populated_country_c',
),
),
),
Now populated_country_c
is the new field in which the data about country will be populated when you choose account in the relate field. So we also need to create that new field. You can do it through studio or manually just by adding new array. Finally your file will look like this
array (
'name' => 'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_id_c',
'name'=>'account_name',
'country_c' => 'populated_country_c',
),
),
),
array (
'name' => 'populated_country_c',
'label'=> 'LBL_POPULATED_COUNTRY'
),
Now when choosing new account from relate field, populated_country_c
will be populated with country_c
field from selected account.
Upvotes: 0