populating fields using a relate field

I’m trying to populating fields using a relate field according to guide:
http://johndopenotes.wordpress.com/2013/03/18/sugarcrm-populating-fields-using-a-relate-field/

So far not achieved any result and not know if I should etner some consideration especially for results in SuiteCRM

THERE ANY ALTERNATIVE TO DO THIS? MAYBE LOGIC HOOK

Doing it that way works fine if its address fields you want to populate. If you are talking about other fields then you will have to write custom Javascript to this.

Follow the instructions bellow:

The first example is how to complete this task using the Sugar Quick Search:

In your FTP client, navigate to your /custom/Extensions/modules/{MODULE NAME}/vardefs
From here you can either create a new file, or edit an existing file. Look for a file name sugarfield_{name_of_your_field}.php that’s the best place to add new code and maintain organization
Open that up and add the following lines:

$dictionary[’{YOUR MODULE NAME}’][‘fields’][’{YOUR FIELD NAME}’][‘populate_list’] = array(‘id’,‘name’,’{NAME OF DB FIELD YOU WANT TO ADD}’);

$dictionary[’{YOUR MODULE NAME}’][‘fields’][’{YOUR FIELD NAME}’][‘field_list’] = array(‘account_id_c’,‘account_name’,’{THE ID OF YOUR FIELD ON THE EDITVIEW LAYOUT}’);

You’ll want to replace anything contained in curly brackets with the specific information for your application. The populate_list is a list of the database field names that you are going to be pulling from the database. The field_list is the list of fields that you are going to be placing these values.
Once you have this in place, go to Admin/Repair/Quick Repair and this process will rebuild the vardefs file in /custom/modules/{MODULE NAME}/Ext/vardefs/vardefs.ext.php.
That’s all there really is to it from a technology standpoint, you can add fields to the arrays to populate more than 1field as well.

The Popup is where things are a little bit more tricky, at least until you know what you need to do. Setting it up in the code is easy enough.

Open /custom/modules/{YOUR MODULE}/metadata/editviewdefs.php
Field your field definition in the file, our full example is included below:
array (
‘name’ => ‘accounts_hdsmi_nym_customer_service_name’,
‘displayParams’ => array (
‘field_to_name_array’ => array(
‘id’=>‘accounts_h66a5ccounts_ida’,
‘name’=>‘accounts_hdsmi_nym_customer_service_name’,
‘accountnum_c’ => ‘account_number_c’,
),
‘additionalFields’ => array(
‘accountnum_c’ => ‘account_number_c’,
),
),
),
),
This is really all the code you need to get this set up. In the field_to_name_array and additionalFields array the key is the database field and the value is the Sugar field you are going to be populating. Pretty straight forward.

This next part is very important regardless of whether it’s working or not. Go into Studio and click on the module that corresponds to the relate field you are working with. (Account relate field requires you to open the Accounts Module). Go into your layouts and find the layout for your Popup List View. If it’s already working, then the custom field that’s being populated is already in that list view. If it’s not working, you’ll want to add that custom field to the list view. This is very important if it is working, because if that custom field is removed from the layout, it will stop working.

Source: http://developer.sugarcrm.com/2011/08/31/howto-using-a-relate-field-to-populate-a-custom-field/

If what you need is only save the content of relate field and not show dinamicaly in EditView, you can create a before_save logic hook.

Regards,
Roberto Dugim
CBR Consultoria
(+55) 11 2227-2321
www.cbrconsultoria.com.br

Hello, andy.
moderately understand the guide, I have many questions, such as:
How do I find this values

  • <ID_FROM_RELATED_MODULE>
    *<ID_OF_RELATE_FIELD>

Hello Dugim:

My case is as follows:
I have a custom module named Contrating_janitor in this module create a field related to the Contacts module (which renowned as Clients).

Being in … / editviewdefs.php custom module delacracion seek the related field. the structure of the statement is:

array (
‘name’ => ‘empleador_c’,
‘studio’ => ‘visible’,
‘label’ => ‘LBL_EMPLEADOR’,
),
1 => ‘name’,
),

What part exactly do I add the code you mention?
on the other hand where or how I can find the “id” of the module to create

Hello BRAGEVALE,

The code you need is samething like that:


array (
	'name' => 'empleador_c',
	'studio' => 'visible',
	'label' => 'LBL_EMPLEADOR',
	'displayParams' => array (
		'field_to_name_array' => array(
			'id'=>'contact_id_c', // probably its is the name of id field, see more bellow
			'name'=>'empleador_c',
			'<NAME OF THE FIELD IN THE RELATED MODULE>' => '<NAME OF THE FIELD WILL BE POPULATE> ',
		),
		'additionalFields' => array(
			'<NAME OF THE FIELD IN THE RELATED MODULE>' => '<NAME OF THE FIELD WILL BE POPULATE> ',
		),
	),
),

An easy way to find the ID OF RELATE FIELD is to use inspect element function of chrome browser by clicking in the select button in the right side of the related field.

1 Like

Hello During, I am grateful, in a first attempt I got an error to delete the penultimate fix), in the code you gave me, put my interest fields Popup List View and run a quick repair and everything is working perfectly.