OS: Linux, Fedora Core 4
SugarCRM Open Source Version 4.5.1b
Apache 2.0
PHP 5.0.4
MySQL: 4.1.20
I have experience with PHP, Object-Relational-Mapping in general (java, ruby ActiveRecord), and SugarCRM (administered a web server for my company serving SugarCRM for 2 years now) and have always found the answers to what I need in these forums, until now.
I received a request to include the 'industry' field from the 'accounts' table as a column in the Contacts module's list view. This has turned out to be more difficult that I thought.
After 1 week of scouring the Forums, Wiki, Web and reading what feels like hundreds of posts, I have to break down and make my first post to this forum.
I found several handfulls of the same type of question asked (a good majority of them never having any comments beyond the initial post) and found the few that had answers vaguely explained (the poster usually gives up settling for their own hack in the module code).
I don't want to settle for a hack; I also don't want my changes to be overwritten by upgrading, or having to manually merge changes with my edited pages.
I figure it should be trivial to include the needed field in such a way as to make it part of the list of fields in Studio for the Contacts module, ListView that show up as columns to choose from (or, more generically, as the list of fields on the left-hand side for the other 2 views).
Accounts table is linked to Contacts via a join table called 'accounts_contacts', so this won't be as simple as two directly-related tables. Formulating various join queries is also trivial in SQL; however I don't want to resort to a 'hack'; i'm sure there has to be a way to do this in the framework provided.
I became positive when I noticed the Contacts module vardefs.php had the following code:
The vardefs.php explanation on the Sugar Wiki site made all of this obvious, and it is formulated in the format that I figure my 'accounts_industry' variable will be, save I thought 'join_name' should point to the join table, not 'accounts', until I looked further and saw the following:PHP Code:'account_name' =>
array (
'name' => 'account_name',
'rname' => 'name',
'id_name' => 'account_id',
'vname' => 'LBL_ACCOUNT_NAME',
'join_name'=>'accounts',
'type' => 'relate',
'link' => 'accounts',
'table' => 'accounts',
'isnull' => 'true',
'module' => 'Accounts',
'dbType' => 'varchar',
'len' => '255',
'source' => 'non-db',
'unified_search' => true,
),
This was still up in the fields declarations, not in the relationships declarations at the bottom as it seemed the vardefs.php explanation on the Wiki site led me to believe, but hey, I KNOW that the existing account_name declaration obviously works, so I figured I would copy the 'account_name' declaration, change 'account_name' to 'account_industry', change 'LBL_ACCOUNT_NAME' to 'LBL_ACCOUNT_INDUSTRY' (also making appropriate variable definition in the language file), and change 'rname'=>'name' to 'rname'=>'industry' so that it looked like this:PHP Code:'accounts' =>
array (
'name' => 'accounts',
'type' => 'link',
'relationship' => 'accounts_contacts',
'link_type' => 'one',
'source' => 'non-db',
'vname' => 'LBL_ACCOUNT',
),
With that, I figured my vardef.php fiddling was done.PHP Code:'account_name' =>
array (
'name' => 'account_name',
'rname' => 'name',
'id_name' => 'account_id',
'vname' => 'LBL_ACCOUNT_NAME',
'join_name'=>'accounts',
'type' => 'relate',
'link' => 'accounts',
'table' => 'accounts',
'isnull' => 'true',
'module' => 'Accounts',
'dbType' => 'varchar',
'len' => '255',
'source' => 'non-db',
'unified_search' => true,
),
'account_industry' =>
array (
'name' => 'account_industry',
'rname' => 'industry',
'id_name' => 'account_id',
'vname' => 'LBL_ACCOUNT_INDUSTRY',
'join_name'=>'accounts',
'type' => 'relate',
'link' => 'accounts',
'table' => 'accounts',
'isnull' => 'true',
'module' => 'Accounts',
'dbType' => 'varchar',
'len' => '255',
'source' => 'non-db',
'unified_search' => true,
),
Next, I moved on to Contact.php and added var $account_industry in the "// These are for related fields" section.
Next, I repaired relationships (and, for good measure, restarted the webserver).
Now, In Studio, I can see my field listed on the left-hand side in Edit- and DetailViews (and if I add it to either view the label shows up fine but never populates with data and I know that contact is linked to an account that has its 'industry' field filled). It doesn't show up in ListView either.
Do I need to explicitly add a XTemplate or Smarty variable mapping somewhere, or is my prior code and/or understanding faulty in some way?
Any help is greatly appreciated.


LinkBack URL
About LinkBacks



Reply With Quote


Bookmarks