Field_to_name_array with flex_relate to Contacts or Accounts

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:

  1. 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)
  2. 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.

I could have sworn I tested this before and it did not work, but I must be mistaken since I tried it again and it works fine.

So below is the answer to how to fetch from a Contacts Relate field.

Still need to determine how to make this work with a Flex_Relate field when the entries in field_to_name_array and population_list need to change based on whether Accounts or Contacts are chosen.

The solution for Relating to a Contacts module from a custom module (AYU_Funds) is very simple.

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_addr_street',
              ),
              'additionalFields' =>
              array (
                'primary_address_street' => 'fund_addr_street',
              ),
            ),
          ),

Where

  • name is (a virtual) field in the Contacts module with the full Contact Name (first_name last_name)
  • id is the field in the Contacts module with the Contact ID
  • primary_address_street is the field in the Contacts module with the Contact Street Address
  • parent_name is the field in the AYU_Funds module holding the Contact Name
  • parent_id is the field in the AYU_Funds module holding the Contact ID
  • fund_address_street is the field in the AYU_Funds module holding the Street Address of the Contact module with the Contact ID

Add a file to custom/Extension/modules/AYU_Funds/Ext/Vardefs/_override_file_with_original_relate_field_definition.php

$dictionary['AYU_Funds']['fields']['parent_name']['populate_list'] = array(
    0 => 'name',
    1 => 'id',
    2 => 'primary_address_city',
    3 => 'primary_address_street',
);
$dictionary['AYU_Funds']['fields']['parent_name']['field_list'] = array(
    0 => 'parent_name',
    1 => 'parent_id',
    2 => 'fund_addr_city',
    3 => 'fund_addr_street',
);

QR&R and all works

Now for the Flex_Relate field …

I am hoping this is NOT the final answer to using a Flex_Relate field, but, as described in

one way to kludge this to work would be to create a before_save logic hook for Accounts and create fields in Accounts which have the same name as the fields in the Contacts and copy the relevant Account information into thse duplicate fileds.

  • Set new Accounts field primary_address_street = billing_address_street
  • Set new Accounts field primary_address_city = billing_address_city

Use primary_address_street and primary_address_city regardless of whether the user selcts Accounts or Contacts.

Hopefully there is a better solution that comeone can suggest becuase this is pure kludge and very restrictive.

If anyone needs to do this with a relate field it does work…

I was struggling with this too!

I wanted to populate a custom account relate field “account_rel_c” based on the relationship to a quote. In the quote the account name is “billing_account” the trick here is that the flex relate field (default) is: “parent_name”

This works for me:

$dictionary['Task']['fields']['parent_name']['populate_list'] = array('name', 'id', 'billing_account');
$dictionary['Task']['fields']['parent_name']['field_list'] = array('name', 'id', 'account_rel_c');

Thanks @p.konetskiy and @Ramblin for your posts!

Make Sure Developer Mode is OFF!!!