Using version 6.3.0 Pro - I have added a relationship between Accounts(primary module) and Notes, this is a one to many relationship. The idea being that every note should be tied to an Account record. In addition to this relationship I have set the Accounts field that this creates (in the notes module) to required and have set it to be dependant on the parent type so it is only required if the parent type is not set to Account. Lastly this field has been set to read only as I want the system to automatically populate this (so users do pick the wrong account).
In the Note class (modules\Notes\Note.php) I have extended the fill_in_additional_parent_fields to the following -
PHP Code:function fill_in_additional_parent_fields() {
parent::fill_in_additional_parent_fields();
//WORKOUT PARENT ACCOUNT RECORD
$action = $_REQUEST['action'];
if (($action == 'SubpanelCreates' || $action == 'EditView') && isset($_REQUEST['record'])){//only do if edit mode
//only need to workout parent account if this is a new note
if ($_REQUEST['record'] == ''){
//get parent type and id so we can load instance later
$parent_Bean_Type = get_singular_bean_name($_REQUEST['parent_type']);
//only do this if not an account
if($parent_Bean_Type != 'Account'){
$parent_Bean_ID = $_REQUEST['parent_id'];
//create new instance of parent
$related_account = new $parent_Bean_Type();
$related_account->retrieve($parent_Bean_ID);
//'accounts' is the link field name - might not be the same for all modules
switch ($parent_Bean_Type){
case 'Quote':
$parent_account = $related_account->get_linked_beans('billing_accounts', 'Account'); //for some reason this breaks the existing code
break;
default:
$parent_account = $related_account->get_linked_beans('accounts', 'Account'); //for some reason this breaks the existing code
}
//TODO - isset is not sufficient for this test...
if (isset($parent_account) && !empty($parent_account)){
$this->accounts_n0e21ccounts_ida = $parent_account->id;
$this->accounts_notes_name = $parent_account->name;
//save the data in the relationship table for this relationship
//$this->load_relationship('accounts_notes');
//$this->accounts_notes->add($parent_account);
//$this->save();
}
}
}
}
}
I am able to get the related Account ID - but as soon as I create a new object to reference this the system seems to forget which 'Parent' record to populate in the view (although the relationship does get saved). I also am not able to get the accounts_notes relationship to save any data in the account_notes_c table while the field is set to read only. NOTE I have setup the system so that every module we use in the system (bar the History related modules) should relate to one Account. The basics of what I am trying to achieve is that all Notes will have a related Account (unless the Parent Record is already an Account) - this relationship should be automatically populated by the system and the selecion field for this relationship will always be set to readonly for all Roles in the system.
If anyone is interested in helping I can create a zip of the system code for you if needed.
(I will create a new custom bean class later once I can get this to work.)


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks