Grab fields from a related record without Sugar Logic?

I am trying to follow this tutorial but I don’t get any fields in studio. Should this work for Suitecrm?


However, you can still do this without Sugar Logic, leveraging the existing vardefs to grab the record directly. Let’s assume you are wanting to grab the employees field from the related Account record into the Contact record; just add this vardef entry into the a file named custom/Extension/modules/Contacts/Ext/Vardefs/accountsemployeefield.php followed by a ‘Quick Rebuild and Repair’

$dictionary['Contact']['fields']['account_employees_c'] = array (
    'name' => 'account_employees_c',
    'id_name' => 'account_id',
    'type' => 'relate',
    'rname' => 'employees',
    'vname' => 'LBL_ACCOUNT_EMPLOYEES',
    'link' => 'accounts',
    'module' => 'Accounts',
    'source' => 'non-db',
    'dbType' => 'non-db',
    'studio' => 'visible',
);

They key parts of the above code snippet is the following:

type, which is set to relate indicating this is a relate field
rname, which points to the field name in the related module record
link, which is the link field in the Contacts vardef which specifies this relationship
module, which is the module which contains the related record

With this vardef entry in place, you can add the account_employees_c field to the DetailView of the Contacts module to have it appear there. Big thanks to Jerry Clark in our Customer Support team for this tip.


Hi Jay007

this approach works in SuiteCRM.

Are you sure that you indexed the right module name in the dictionary array? It’s an easily made mistake.


$dictionary['Contact']

Regards,
Jan Siero

Yes I copied and pasted the very same as in tutorial but the field never shows in studio. I re installed,Suitecrm and also checked all permissions etc. below is my php file in custom/modules/Contacts/Ext/Vardefs

$dictionary['Contact']['fields']['account_employees_c'] = array (
    'name' => 'account_employees_c',
    'id_name' => 'account_id',
    'type' => 'relate',
    'rname' => 'employees',
    'vname' => 'LBL_ACCOUNT_EMPLOYEES',
    'link' => 'accounts',
    'module' => 'Accounts',
    'source' => 'non-db',
    'dbType' => 'non-db',
    'studio' => 'visible',
);

I do a repair and rebuild then go to studio and select contacts but the field is not there. I was trying this on 2 different modules first and when I couldn’t get it working I said I would try it on the same 2 modules as in the tutorials as it doesn’t use custom fields.

Hi Jay007,

you copied the file in the wrong directory, it should go into (filename you may choose yourself):


custom/Extension/modules/Contacts/Ext/Vardefs/account_employees.php

After having copied this file to the right location and doing a repair and rebuild, your field should appear in studio as “LBL_ACCOUNT_EMPLOYEES”

To name it to “Employees”, don’t forget to create a language file in


custom/Extension/modules/Contacts/Ext/Language/en_us.account_employees.php

like


<?php
$mod_strings['LBL_ACCOUNT_EMPLOYEES'] = 'Employees';

To optimize your vardefs, I’d suggest you disable massupdate for this field and add the join table and join link table so SuiteCRM querying is drastically simplified like this:


$dictionary['Contact']['fields']['account_name']['join_link_name'] = 'accounts_contacts_link';

$dictionary['Contact']['fields']['account_employees_c'] = array (
	'name' => 'account_employees_c',
	'id_name' => 'account_id',
	'type' => 'relate',
	'rname' => 'employees',
	'vname' => 'LBL_ACCOUNT_EMPLOYEES',
	'link' => 'accounts',
	'module' => 'Accounts',
	'source' => 'non-db',
	'dbType' => 'non-db',
	'studio' => 'visible',
	'massupdate' => false,
	'join_name'=>'accounts',
	'join_link_name'=>'accounts_contacts_link',
);

Regards,
Jan Siero

It works, cant believe I missed that. :blush: Thanks very much…

If you want to retrieve a custom field from the related record, it doesn’t work.

For example:

$dictionary['Contact']['fields']['account_employees_c'] = array (
    'name' => 'account_employees_c',
    'id_name' => 'account_id',
    'type' => 'relate',
    'rname' => 'anyfield_c',
    'vname' => 'LBL_ACCOUNT_EMPLOYEES',
    'link' => 'accounts',
    'module' => 'Accounts',
    'source' => 'non-db',
    'dbType' => 'non-db',
    'studio' => 'visible',
);

The log shows that that query built does not join the accounts_cstm table.

Any suggestion ?

Hi aureh12,

You can’t make this work with custom fields created with studio.

However, you can also create custom fields with vardefs, please refer to this post on how to create such a field:

The creation of the field is realised by the first two files, the other two are for making it visible in the related module.