Update:
Question 1 - using with Contacts - has been resolved - see below
Question 2 - using with Flex_relate is still a mystery so any thoughts or ideas would be appreciated.
Using field_to_name_array in editviewdefs.php and populate_list/field_list arrays in the vardefs, with great help from @p.konetskiy at
I was able to have fields in my custom module (AYU_Funds) auto-populated from fields in a core module (FP_events) when a Relate field from AYU_Funds to FP_events was populated.
I have been able to duplicate the functionality when the Relate field from AYU_Funds to Accounts is setup.
However, some things I have NOT been able to figure out are:
- How to I configure the populate_list array when I am Relating to the Contacts module (There is no “full_name” field in the Contacts module database table)
- How do I make this work with a Flex_Relate field pointing to one of Accounts or Contacts when the left side of the field_to_name array and the populate_list array will be different, depending on the choice made for Parent_Type (Accounts or Contacts)?
Details - and challenges - explained below
Any Help is appreciated
To have fields in my custom module (AYU_Funds) auto-populate from fields in the Accounts module when a Relate field in the AYU_Funds module points to the Accounts module (with help from @p.konetskiy ) I did the following:
To have it work when the user uses the Select button to choose the Account:
In custom/modules/AYU_Funds/metadata/editviewdefs.php
1 =>
array (
'name' => 'parent_name',
'studio' => 'visible',
'label' => 'LBL_PARENT_NAME',
'displayParams' =>
array (
'field_to_name_array' =>
array (
'name' => 'parent_name',
'id' => 'parent_id',
'primary_address_street' => 'fund_address_street',
),
),
),
Where:
- name is the field in the Accounts module with the Account Name
- id is the field in the Accounts module with the Account ID
- primary_address_street is the field in the Accounts module with the Account Street Address
- parent_name is the field in the AYU_Funds module holding the Account Name
- parent_id is the field in the AYU_Funds module holding the Account ID
- fund_address_street is the field in the AYU_Funds module holding the Street Address of the Account
To have it work when the user uses the auto-complete function and clicks on one of the options presented for the Account:
add a file to custom/Extension/modules/AYU_Funds/Ext/Vardefs/_override_file_with_original_relate_field_definition.php with
<?php
$dictionary['AYU_Funds']['fields']['parent_name']['populate_list'] = array(
0 => 'name',
1 => 'id',
2 => 'primary_address_street',
);
$dictionary['AYU_Funds']['fields']['parent_name']['field_list'] = array(
0 => 'parent_name',
1 => 'parent_id',
2 => 'fund_addr_street',
);
With the above setup, all worked well for both the Select and auto-complete options
However:
Regarding question 1), doing this with Contacts, there is no “full name” field in the Contacts database table that I can use with auto-populate to populate the parent_name field (concatenation of first_name and last_name) in AYU_Funds so I do not know what to put into the left side of the first entry in the population_list array in the vardefs file. I was actually able to get things to work using the Select option by putting ‘full_name’ into the first entry in the field_to_name array in editviewdefs.php which gave us the code below and allowed things to work when the Select button was used to identify the relationship"
1 =>
array (
'name' => 'parent_name',
'studio' => 'visible',
'label' => 'LBL_PARENT_NAME',
'displayParams' =>
array (
'field_to_name_array' =>
array (
'full_name' => 'parent_name',
'id' => 'parent_id',
'primary_address_city' => 'fund_addr_city',
'primary_address_street' => 'fund_addr_street',
),
'additionalFields' =>
array (
'primary_address_city' => 'fund_addr_city',
'primary_address_street' => 'fund_addr_street',
),
),
),
But when I tried the same with the populate_list array, using ‘full_name’ as the first entry did NOT allow the user to use the auto-complete function to populate the AYU_Funds fields.
Regarding question 2) doing this with a flex_relate field that allows a user to Select as parent_type either Accounts or Contacts, I would need to change the entries for the first two entries in the the left side of the field_to_name array in editviewdefs.php and the first two entries in the population_list array in the vardefs file. Neither the vardefs file nor the editviewdefs file are actually processed as normal php files so I cannot use if…then…else statements in either of these files and even if I could, I do not know how to fetch the parent_type (Accounts or Contacts) that would let me use the correct leg of the if…then…else condition.
Any ideas?
I am on SuiteCRM v7.12.8 if that is relevant.