Many of you will remember this blog post from a few weeks back, where I showed you how to add a field from a related module by leverage Sugar Logic. While this is an easy to use method that works great for simple situations and doesn’t require any code level customization, there can be a bit of overhead when using lots of Sugar Logic formulas on a single record as there’s lots of overhead involved in this approach ( for example, if you are using 40+ Sugar Logic formulas on a record ). Plus, it doesn’t currently work in CE as it doesn’t support Sugar Logic.
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.
Edited 7/30/2012 – Replaced ‘join_name’ with ‘link’ in examples above.