Field to name Array in related in autocomplete

Hello,
i’ve successfully populated custom text field in ModuleB by selecting related field that points in ModuleA, however this does not works if instead clicking the button near to related field the autocomplete has been used.

Does anyone have a clue regarding how to let it works also with autocomplete?

Many Thanks

@rainolf
There are several standard decision. Give some more details about place and form where you want to do it.

Hello,
currently i’m doing some test in Case module with relate field referenced to Account.
Like this:

2 => 
        array (
          0 => 'type',
          1 => 
          array (
            'name' => 'account_name',
            'displayParams' => 
            array (
              'field_to_name_array' => 
              array (
                'name' => 'account_name',
                'id' => 'account_id',
                'industry' => 'account_industry_c',
                'account_type' => 'account_type_c',
              ),
            ),
          ),
        ),

Where:
account_name is the name of Account relate filed in Case module
account_id is the hidden id of Account relate filed in Case module
‘industry’ is the parent Account filed while ‘account_industry_c’ is the destination Case field
‘account_type’ is the another parent Account filed while ‘account_type_c’ is another destination Case field

Of Course, i am working in EditViewDefs of Case module, and this is just a proof of concept.
Then i will move to my real custom module.

Thanks

@rainolf
Your code correct absolutely. I use this metod in my systems too.
I made your fields (‘account_industry_c’ and ‘account_type_c’) to use Studio in my test platform. After then I copied your code to file - custom/modules/Cases/metadata/editviewdefs.php and added the fields (‘account_industry_c’ and ‘account_type_c’) too. All working!
If data don’t saved there is problem in somewhere else.

Sorry but probably i was not able to explain me well.
The code above works well just when you use the select button in related field in order to choose Accounts from popup search modal.
See attached:


But when you use autocomplete by typing first chars of Account name in related field and then select teh result it doesn’t retrieve anything in the respective fileds.
See attached:

So the question is:“How to fire filed_to_name_array” also during autocomplete?

Many thanks

@rainolf
It was interesting case and the solution is very easy. I think that it may be interesting for a lot people.
Let’s add the custom file - ‘custom/Extension/modules/Cases/Ext/Vardefs/account_name.php’

$dictionary['Case']['fields']['account_name']['field_list']=
        array('account_name','account_id','account_industry_c','account_type_c');
$dictionary['Case']['fields']['account_name']['populate_list']=
        array('name','id','industry','account_type');
3 Likes

This is an excellent solution. I didn’t know it was so easy to configure SQS (the find-as-you-type search used in SuiteCRM).

@pgr
SuiteCRM keeps many secrets yet. :wink: :joy:

1 Like

Yes, i agree with you.
Anyway it works like a charm!
Thanks guys

Hi,
i am doing additional test and i’ve found in both situation(popup selection and quick search) that checkboxes cannot be populated. Moreover also option in dropdown cannot work if Name differs from value because it seems retrieving only the option name and not its own value.

Anyone came across this situation?
What would be an alternative way to do it(maybe with js on view) where also some source fields must be trasformed before being written to destination(ex: sum 2 source fields into one destination)?

Another issue i’ve found is regarding currency fields.
In the source module has only 2 digits in decimal places while on destination 6.

Many thanks

@rainolf
I think that the field of type datetime will have problems too.
Javascript should be done for different types fields. popup selection and quick search get data only but they don’t process them. The data can get into the hidden field and the javascript will process them.

But I think that it can use text fields in more situations. If data is taken from ‘parent’ module they should not be changed in ‘child’ module.

@p.konetskiy would this method be suitable to have a relate field in the conversion process? I’m trying to add a relate field to converdefs.php, not sure how I would implement it there.

Sorry I already figured this one out. This wasn’t exactly what I was trying to do. I just wanted to add a normal relate field to the converdefs.php to populate on conversion. However, this gave me a good idea what I needed to do.

See: https://community.suitecrm.com/t/adding-a-relate-field-form-to-the-convert-leads-layout/77668

1 Like

@rainolf

@p.konetskiy

It seems you are the guy with all the answers (at least for me) lately

You were right; this is the exact situation I am facing: If the user identifies the related record by selecting the entry, the field_to_name_array works as expected and the local field is populated. But if the user starts typing in the field (instead of using the Select button) and chooses from one of the auto-complete suggestions, there is nothing populated in the local field.

I have tried using field_to_name_array to copy a text field to a text field
–Select works, choosing from the autocomplete options does not
I have tried using field_to_name_array to copy over a datetime field
–Select works, choosing from the autocomplete options does not

I was excited to see you have found a solution but I cannot get your solution to work. Any suggestions would really be appreciated.

In my case I am using a relationship (one-to-many) (and also a flex_relate field but we can deal with that later) so that may be complicating my situation. The field_to_name_array solution works for the one-to-many relationship as long as the user uses the Select button, but not if the user uses the autocomplete method.

Here is what I have

I have a custom module AYU_Funds, which records donations made at a Fund-Raising Event, with the Event being created by the FP_events core module.

I have created a One->Many relationship between AYU_Funds and FP_events. Each Fund-Raiser donation can only be associated with one Event but an Event can have many Fund Raiser Donations.

In custom/modules/AYU_Funds/metadata/editviewdefs.php

          0 => 
          array (
            'name' => 'fp_events_ayu_funds_1_name',
            'displayParams' => 
            array (
              'field_to_name_array' => 
              array (
                'name' => 'fp_events_ayu_funds_1_name',
                'id' => 'fp_events_ayu_funds_1fp_events_ida',
                'test_field_to_name_c' => 'receive_field_to_name_c',
                'additionalFields' => 
                array (
                  'test_field_to_name_c' => 'receive_field_to_name_c',
                ),
              ),
            ),
          ),

Where:

  • name is the name from the FP_events module
  • id is the idfrom the FP_events module
  • test_field_to_name_c is a text field (created in Studio) in the FP_events module
  • fp_events_ayu_funds_1_name is the holder of the Event name in the AYU_Funds module
  • fp_events_ayu_funds_1fp_events_ida is the holder of the Event id in the AYU_Funds module
  • receive_field_to_name_c is a text field (created in Studio in AYU_Funds) to hold the test_field_to_name_c content from the FP_events module

I have tried it with and without the additionalFields array and it makes no difference. I was told previously to use additionalFields for fields beyond the initial lookup fields (name and id) but if you think this is an issue, please advise.

As long as the user uses the Select button, just having the above makes the field_to_name_array work fine: the receive_field_to_name_c field in AYU_Funds is populated with the content of the test_field_to_name field from FP_events

But if the user uses the auto-complete and chooses one of the options put forward by the aut-complete, no content is added to the AYU_Funds field

So, to try and use your solution, I then added, into custom/Extension/modules/AYU_Funds/Ext/Vardefs/fieldToName.php

$dictionary['AYU_Funds']['fields']['fp_events_ayu_funds_1_name']['populate_list'] = array(
    'id','name','test_field_to_name_c',
);
$dictionary['AYU_Funds']['fields']['fp_events_ayu_funds_1_name']['field_list'] = array(
    'fp_events_ayu_funds_1fp_events_ida','fp_events_ayu_funds_1_name','receive_field_to_name_c',
);

After a Quick Repair and Rebuild, nothing changed

Using the Select button, the field content is pulled over
Using the auto-complete, nothing is pulled over

Any suggestions?

P.S.

I did see your post at

but I don’t understand where your code goes or if that code is applicable to my situation.

@Ramblin

  1. I don’t know anything about array additionalFields.
  1. Check the file cache/modules/AYU_Funds/AYU_Fundsvardefs.php . It should have populate_list and field_list arrays in the field array $GLOBALS["dictionary"]["AYU_Funds']["fields"]["fp_events_ayu_funds_1_name"]
  2. If you are using the opcache module in php, you may need to restart the web server.
  3. I use it in SuiteCRM 7. It works for all my projects.

@p.konetskiy

One additional piece of information. Not sure it is relevant but I am on SuiteCRM v7.12.8

I did shutdown and restart the server

I removed the additionalFields array from the editviewdefs.php entry, just in case it was causing an issue. It did not make any difference but I left it out just in case.

I did check the cache at cache/modules/AYU_Funds/AYU_Fundsvardefs.php . Neither of the array entries

$dictionary['AYU_Funds']['fields']['fp_events_ayu_funds_1_name']['populate_list'] = array(
    'id','name','test_field_to_name_c',
);
$dictionary['AYU_Funds']['fields']['fp_events_ayu_funds_1_name']['field_list'] = array(
    'fp_events_ayu_funds_1fp_events_ida','fp_events_ayu_funds_1_name','receive_field_to_name_c',
);

were there. Good catch. Not sure what is going on. The cache file is being updated with a QR&R; it is just not including the two array definitions.

Both array definitions were in custom/modules/AYU_Funds/Ext/Vardefs/vardefs.ext.php so the QR&R did its job and consolidated the vardefs for AYU_Funds.

But for some reason the two array definitions did not get included in the cache file.

I even tried re-defining the arrays by explicitly declaring the keys with

$dictionary['AYU_Funds']['fields']['fp_events_ayu_funds_1_name']['populate_list'] = array(
    0 => 'id',
    1 => 'name',
    2 => 'test_field_to_name_c',
);
$dictionary['AYU_Funds']['fields']['fp_events_ayu_funds_1_name']['field_list'] = array(
    0 => 'fp_events_ayu_funds_1fp_events_ida',
    1 => 'fp_events_ayu_funds_1_name',
    2 => 'receive_field_to_name_c',
);

but that made no difference

I even tried changing the array definitions so the populate_list and field_list were switched as in

$dictionary['AYU_Funds']['fields']['fp_events_ayu_funds_1_name']['field_list'] = array(
    0 => 'id',
    1 => 'name',
    2 => 'test_field_to_name_c',
);
$dictionary['AYU_Funds']['fields']['fp_events_ayu_funds_1_name']['populate_list'] = array(
    0 => 'fp_events_ayu_funds_1fp_events_ida',
    1 => 'fp_events_ayu_funds_1_name',
    2 => 'receive_field_to_name_c',
);

but that made no difference, so I put it back to the original. I guess it is not a surprise that it made no difference since the definitions are not getting to the cache file.

It is the same as before:

  • When using Select the content is transferred over
  • When using auto-complete, the content is not transferrred over

Three questions:

  1. is there a setting somewhere in SuiteCRM that would interfere with the auto-complete functionality
  2. what could possibly prevent something that was in
    custom/modules/AYU_Funds/Ext/Vardefs/vardefs.ext.php
    from being included in
    cache/modules/AYU_Funds/AYU_Fundsvardefs.php

Thank you for helping

@Ramblin

  1. No
  2. Try to delete cache file.

@p.konetskiy

Success!

I did delete the cache file and after a QR&R the chache file was regenerated but with the same result

I did get a couple of things figured out and the cache file now does include the array definitions and al,l is working for text fields and datetime fields

  • When using Select the content is transferred over
  • When using auto-complete, the content is transferred over

What I did figure out was that I needed to ensure that the array definitions were loaded AFTER the original definition of the name variable fp_events_ayu_funds_1_name. Since the original defninition of the name vaiable was created in Studio (as a one->to->many relationship), it named the vardef file _override_fp_events_ayu_funds_1_AYU_Funds.php . Since I had named my file without the override prefix, the original vardef for fp_events_ayu_funds_1_name wiped out my array definitions and prevented them from being added to the cache file.

I renamed my file to be loaded after the original vardef file so I renamed it to _override_fp_events_fieldToName.php and now the cache file does include the array definitions.

So all is working, including a datetime field which I have added.

I now need to do the same for a Flex_Relate field. Let’s hope it goes well …

Thank you for helping on this

@p.konetskiy

I created a new post at

I cannot figure out how to get the above to work with a Flex_Relate field pointing to either Accounts or Contacts

I thought it best to not hijack this thread with a partially-off-topic question.

Any thoughts you have on the new post would be appreciated.

hey @p.konetskiy you seem to be the guru of this topic. I just tried it out and it works great! I did have delete my cache file for it to work, I think this is definitely an important step. Quick question kind of related…

I’m adding this to a custom module (Transportation) and I’ve created Shipments (trans_Shipments) to capture shipments. Shipments ship to an account and I’ve used this to populate the address.

If I want to ensure this gets into my custom module package for export do I need to put it in:
/custom/modulebuilder/builds/Transportation/trans_Shipments/account_name.php or where do I put it so it remains part of the module builder if I have to rebuild it , or export the module?
Or will it just export if I just have it in the /custom/Extension/modules/trans_Shipments/Ext/Vardefs/account_name.php

@pstevens
I don’t use the Module Builder. I create the installation package manually every time.
The file will add new field for system or custom module.

Thank you for such a high rating. :slightly_smiling_face:

1 Like