Another customization that appears not to have a solution posted to the forums is how to get around the limited view functionality on the standard Sugar virtual fields for one-to-many and one-to-one relationships. This is actually quite easy and basically requires only 1 line of code in a logic_hook or custom module save function.
Here are the steps:
1) Create a standard relate field name/id pair in the "right hand side" of the relationship.
2) Add in your favorite flavor of "initial-filter" or, as I have done, change the id field to an enum using a function that returns a filtered array that feeds the select list option list (dropdown).
3) Create a relationship entry in the primary module.
4) Deploy the module relationship change with any necessary Quick Repairs.
5) Go lookup the field name for the rhs_key that was created for the relationship. You can find that either in the database table record or the vardefs directory for the right hand side module(custom/modules/<rhs_module_name>/Ext/Vardefs/vardefs.ext.php).
6) Add a save() function to the custom module or as a logic_hook. In that function, and before you call parent::save(), add one line of code to assign the value of the relate field id to the virtual rhs_key field.
For example, if I have custom module 'Subscribers' and I want to relate it to Accounts, create an 'account' relate name field that also creates an relate id field that is actually stored in the database (i.e. account_id_c). Then, add the relationship in studio or modulebuilder. After deploying the relationship, assume there is a rhs_key name of accounts22cfdsubscr_ida.
In a logic hook or inside the custom module code, add a field equate command between the relate id and the rhs_key field. Deploy this code and let Sugar handle the rest.
Note: If you're using modulebuilder, be certain to delete any auto-generated virtual (non-db) fields in the view definitions so that you don't duplicate the relate field in the view.
Sample Code:
Code:<?php function save($check_notify = FALSE) { $this->accounts22cfdsubscr_ida = $this->account_id_c; $parent::save($check_notify); } ?>


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks