Results 1 to 2 of 2

Thread: Account to Notes Relationship

  1. #1
    andywest is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    41

    Default Account to Notes Relationship

    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.)

  2. #2
    andywest is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    41

    Default Re: Account to Notes Relationship

    I ended up making a call to the set_relationship method. Seems to work ok. Not sure if that is the most efficient way of doing it though.

    I am thinking of creating a new acl field level to allow readonly fields that the system has populated to save, or at least one that is a create only access control level - anyone had any experience of these?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do I add relationship to Notes in ModuleBuilder?
    By djmorton in forum Developer Help
    Replies: 1
    Last Post: 2010-08-26, 06:22 PM
  2. Replies: 0
    Last Post: 2010-02-23, 02:15 PM
  3. Replies: 3
    Last Post: 2009-09-16, 05:58 PM
  4. relationship between Notes and custom
    By Rudi Mentär in forum Developer Help
    Replies: 0
    Last Post: 2009-01-22, 01:03 PM
  5. Viewing Account Notes In Contacts Tab
    By Chopwood in forum Help
    Replies: 3
    Last Post: 2008-06-23, 03:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •