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