Automatic field filling

Hi,
I explain my request, I hope someone can help me:
I have created my own form and linked it to the suite user form. When I create a new record in my form, I have entered the first and last name fields in the form and there is also the user search field.

user

I would like the first and last name fields to be filled in automatically once the user has been selected.
Does anyone know how to do this? Thank you

@fab

Look at the post:

p.konetskiy,
I tried to follow the solution you proposed but I didnā€™t quite understand if both files have to be modified, Vardef with:

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

and custom/Extension/modules/Cases/Ext/Vardefs/account_name.php with:

$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');

Or is it just the last modification I have to make?
In any case Iā€™ve tried both, both modifying the two files and just the last one, but I donā€™t see any results, itā€™s likely that Iā€™m doing something wrong, maybe in the variable assignment.

I have my custom module (letā€™s call it module_a), inside it is the link field to the Users module, in

custom/Extension/modules/module_a/Ext/Vardefs/_override_sugarfield_last_name_c.php

I have inserted your changes

$dictionary['module_a']['fields']['last_name_c']['field_list']=
        array('last_name_c');
$dictionary['module_a']['fields']['last_name_c']['populate_list']=
        array('name');

@fab

  1. You should do Quick Repair and Rebuild after change files.
  2. Array displayParams in file editviewdefs.php is working for popup window.
  3. Arrays field_list and populate_list in file account_name.php is working for quick search in line.
  4. Donā€™t use files ...Vardefs/_override... because itā€™s making Studio.

OK, so these modifications are not needed in my case? How can I fill in the Last Name and First Name fields after searching within Users and selecting the user?

Edit your file custom/modules/module_a/metadata/editviewdefs.php/ (for popup only).

 'displayParams' => 
            array (
              'field_to_name_array' => 
              array (
                'name' => 'user_name',  //write correctly name of module_a into value
                'id' => 'user_id', //write correctly name of module_a into value
                'last_name' => 'last_name_c',
                'first_name' => 'first_name_c',
              ),
            ),

Finally, after many attempts, I managed to get it working, thank you p.konetskiyā€¦ the filling works perfectly, only two things need to be fixed:

  1. When I select the user, the user field is replaced with last_name and first_name (user_name appears at the beginning).

  2. As also mentioned in the link you posted at the beginning, the autofill only works for the popup, but not if I use inline compilation. I followed the steps you suggest to solve it, by inserting these lines:

    $dictionary[ā€˜module_aā€™][ā€˜fieldsā€™][ā€˜assigned_user_nameā€™][ā€˜populate_listā€™]= array(ā€˜last_nameā€™);
    $dictionary[ā€˜module_aā€™][ā€˜fieldsā€™][ā€˜assigned_user_nameā€™][ā€˜field_listā€™] = array(ā€˜last_name_cā€™);

But nothing happens.
The thing Iā€™ve noticed is that the link field to the Users module, is called assigned_user_name (in editviewdefs), but if I look in the custom/Extension/ā€¦ folder. folder, I find the file
_override_sugarfield_user_id_c.

However, I have tried both editing this file and creating the file
assigned_user_name.php or user_id_c.php, but nothing happens.

@fab

You should do the arrays:

$dictionary["module_a"]["fields"]["assigned_user_name"]["populate_list"]= array(
    "id",
    "name",
     "last_name"
);
$dictionary["module_a"]["fields"]["assigned_user_name"]["field_list"] = array(
    "assigned_user_id",
    "assigned_user_name",
    "last_name_c"
);

Iā€™ve tried everything, but itā€™s as if the file
suitecrm\custom\Extension\modules\module_a\Ext\Vardefs\assigned_user_name.php
is not taken into account at all, no matter what I insert, even after the Q&R

UPDATE:
by doing various tests I saw that by modifying the code like this:

$dictionary[ā€˜module_aā€™][ā€˜fieldsā€™][ā€˜assigned_user_nameā€™][ā€˜populate_listā€™]= array('name','id','last_name','first_name');

$dictionary[ā€˜module_aā€™][ā€˜fieldsā€™][ā€˜assigned_user_nameā€™][ā€˜field_listā€™] = array('assigned_user_name','last_name_c','last_name_c','last_name_c');

when I change inline the user field, the content of the last name is changed, but with its id, whatever else I put in correspondence of the id, that is not last_name_c, nothing appears

Your arrays will be like that:

$dictionary['module_a']['fields']['assigned_user_name']['populate_list']=array(
  'name',
  'id',
  'last_name',
  'first_name'
);
$dictionary['module_a']['fields']['assigned_user_name']['field_list']=array(
  'assigned_user_name',
  'assigned_user_id',
  'last_name_c',
  'first_name_c'
);

No, nothing, I tried, but the field is only filled with the id and setting it this way:

$dictionary['module_a']['fields']['assigned_user_name']['populate_list']=array(
  'name',
  'id',
  'last_name',
  'first_name'
);
$dictionary['module_a']['fields']['assigned_user_name']['field_list']=array(
  'assigned_user_name',
  'last_name_c',
  'last_name_c',
  'first_name_c'
);

@fab
I checked this situation. Iā€™m sorry but for modules which have parent object as Person(Contacts, Employees, Leads, Prospects, Users) works other algorithm. It requires additional code to be written. Itā€™s possible, but with addition code only.

Thanks for this clarification, I was starting to go crazyā€¦ as I told you, the field fills it, but only with the id, can you tell me what additional code I need to insert?

@fab
Do you want that I will write it for you?

It would be niceā€¦ :grin: but you just need to know at least where to put your hands, what to modify, what kind of code to add

@fab
Here i can write only that the file modules/Home/quicksearchQuery.php is entry point for search when user print symbols on form.
If you want more information you can write me to directly.

p.konetskiy
I give up, Iā€™ve seen the files:

home/QuickSearch
home/quicksearchQuery
include/QuickSearchDefaults

trying to modify them in some way, but I can not solveā€¦ if you have other suggestions I listen gladly

@fab

  1. This is part of javascript on editview page:
sqs_objects['EditView_assigned_user_name']={
    "form":"EditView",
    "method":"get_user_array",
    "field_list":[
        "user_name","id","last_name","first_name"
    ],
    "populate_list":[
        "assigned_user_name","assigned_user_id","name_l_c","name_f_c"],
    "required_list":["assigned_user_id"],
    "conditions":[
        {
            "name":"user_name",
            "op":"like_custom",
            "end":"%",
            "value":""
        }
    ],
    "limit":"30",
    "no_match_text":"No Match"
};
  1. It is builded by function ā€œcreateQuickSearchCodeā€ of file ā€œinclude/TemplateHandler/TemplateHandler.phpā€ and some functions of file ā€œinclude/QuickSearchDefaults.phpā€ .

  2. You can see different metods. The object ā€œUserā€ use method ā€œget_user_arrayā€.

4.a. You should make custom class ā€œquicksearchQueryCustomā€ as extends ā€œquicksearchQueryā€ in file ā€œcustom/modules/Home/QuickSearch.phpā€ and write function ā€œget_user_arrayā€ carefully.

or

4.b. You should make custom class ā€œQuickSearchDefaultsCustomā€ as extends ā€œQuickSearchDefaultsā€ in file ā€œcustom/include/QuickSearchDefaults.phpā€ and write function ā€œgetQSUserā€ which should use function ā€œgetQSParentā€ as an example.

  1. One change in array ā€œpopulate_listā€ for field ā€œassigned_user_nameā€.
$dictionary['Account']['fields']['assigned_user_name']['populate_list']=array(
  'user_name',
  'id',
  'last_name',
  'first_name'
);
$dictionary['Account']['fields']['assigned_user_name']['field_list']=array(
  'assigned_user_name',
  'assigned_user_id',
  'last_name_c',
  'first_name_c'
);

This is a full instruction. I am tested 4.a.

1 Like

I have to be honest, I donā€™t really understand how to create the function

get_user_array

anyway, thanks to your advice I solved it this way:
I modified the file

QuickSearchDefault.php

in the function

getQSUser

I replaced the line

'method' => 'get_user_array',

with

'method' => 'get_contact_array',

and added the line

'modules'=>array('Users'),

Now it works, the inline search is only done by last name, but thatā€™s acceptable. I donā€™t know what this change does to other modules, for now itā€™s fine.
Thanks a lot p.konetskiy