Results 1 to 9 of 9

Thread: Relate field and subpanel

  1. #1
    ranthony is offline Member
    Join Date
    Dec 2007
    Posts
    9

    Default Relate field and subpanel

    Using Sugar Community Edition 5.0.0a (Build 3120), I've been attempting to get a subpanel for my custom module under the Accounts module. I tried following these directions:
    http://www.sugarcrm.com/wiki/index.p...s_in_Sugar_5.0

    That didn't work so well, as I keep getting errors when loading the Accounts module such that no subpanels show up. I'm sure it's something in my config files, but I certainly can't find it. The error is:
    Fatal error: Call to a member function getQuery() on a non-object in \data\SugarBean.php on line 2489

    Here's what I did. I created a custom module with a basic template. It's a module to associate a GoToMyPC account with a client Account. I added a Relate field that linked to Accounts name Account. This created an Account field and an account_id field. Next I modified the layouts to show the Account field on the edit and detail layouts. Then I deployed it.

    I then edited the three files I understand I need in \custom\Extension\modules\Accounts\Ext\. First vardefs.php which went in the Vardefs\ folder. I've tried the rhs_table with both the _cstm at the end and not. I have an account_id field in my goto1_gotomypc table, so I figured that was the place to go. That didn't work, so I added the _cstm like the step by step link above suggests. Also a no-go.

    Code:
    $dictionary['Accounts'] = array(
    	'relationships' => array (
    		'GoTo1_GoToMyPC_accounts' => array (
    			'lhs_module' => 'Accounts',
    			'lhs_table' => 'accounts',
    			'lhs_key' => 'id',
    			'rhs_module' => 'GoTo1_GoToMyPC',
    			'rhs_table' => 'goto1_gotomypc_cstm',
    			'rhs_key' => 'account_id',
    			'relationship_type' => 'one-to-many',
    		),
    	),
    	'fields' => array (
    		'goto1_gotomypc_link' => array (
    			'name' => 'goto1_gotomypc_link',
    			'type' => 'link',
    			'relationship' => 'GoTo1_GoToMyPC_accounts',
    			'source' => 'non-db',
    			'vname' => 'LBL_GOTOS'
    		),
    	),	
    );
    Next the layoutdefs.php that goes in the Layoutdefs\ folder. This one seems more straightforward. Use the same fieldname from above and that's about it.

    Code:
    $layout_defs['Accounts']['subpanel_setup']['goto1_gotomypc'] = array (
      'order' => 100,
      'module' => 'GoTo1_GoToMyPC',
      'subpanel_name' => 'default',
      'get_subpanel_data' => 'goto1_gotomypc_link',
      'title_key' => 'LBL_GOTO1_GOTOMYPC_SUBPANEL_TITLE',
      'top_buttons' => array( // this array defines the top buttons
         array('widget_class' => 'SubPanelTopCreateButton'),
         array('widget_class' => 'SubPanelTopSelectButton', 'mode'=>'MultiSelect')
       ),
    );
    Last the language file en_us.custom.php that goes in the Language\ folder. I'm just covering the two labels I used above.

    Code:
    $mod_strings = array (
      'LBL_GOTO1_GOTOMYPC_SUBPANEL_TITLE' => 'GoToMyPC',
      'LBL_GOTOS' => 'GoToMyPCs',
    );
    I've been trying to finagle this thing into giving me subpanels for a couple days in between other projects, moving strings around, using differnet fieldnames, different tablenames, etc. I'm afraid I just don't have the experience to track down where this is causing me problems. Anybody out there able to point out my flaws so that I can correct them? Any other info needed to try?

    Thanks!

    Ryan

  2. #2
    dpatech is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    NC
    Posts
    287

    Default Re: Relate field and subpanel

    Try changing the name of you relationship to the match the name of the Link field so that both are named

    'goto1_gotomypc_accounts'

    Also, the name of the table in the relationship record should be 'goto1_gotomypc', not 'goto1_gotomypc_cstm' as I believe your account_id field should be in the base table not the custom table.

    If this doesn't just work, change your logging level to debug (in log4php.properties), bring up an account record and then review the logfile. Generally you will see an error finding the subpanel, loading the relationships, or generating the query. Post that error and I can help you sort through the issue.
    - Sugar Team
    dpa Technology LLC
    e-mail: dpaDeveloper@dpatechnology.com
    web: http://www.dpatechnology.com

  3. #3
    ranthony is offline Member
    Join Date
    Dec 2007
    Posts
    9

    Default Re: Relate field and subpanel

    Thanks for taking a look at this. I agree that the rhs_table should be goto1_gotomypc, as that table certainly does have an account_id field in it. I now have this in my vardefs.php file:

    Code:
    $dictionary['Accounts'] = array(
    	'relationships' => array (
    		'GoTo1_GoToMyPC_accounts' => array (
    			'lhs_module' => 'Accounts',
    			'lhs_table' => 'accounts',
    			'lhs_key' => 'id',
    			'rhs_module' => 'GoTo1_GoToMyPC',
    			'rhs_table' => 'goto1_gotomypc',
    			'rhs_key' => 'account_id',
    			'relationship_type' => 'one-to-many',
    		),
    	),
    	'fields' => array (
    		'goto1_gotomypc_accounts' => array (
    			'name' => 'goto1_gotomypc_accounts',
    			'type' => 'link',
    			'relationship' => 'GoTo1_GoToMyPC_accounts',
    			'source' => 'non-db',
    			'vname' => 'LBL_GOTOS'
    		),
    	),	
    );
    Loading that and turning the logger to DEBUG shows these two lines:
    02/15/08 11:27:20,683 [6920] DEBUG SugarCRM - SugarBean.load_relationships, Loading relationship (goto1_gotomypc_accounts).
    02/15/08 11:27:20,684 [6920] DEBUG SugarCRM - SugarBean.load_relationships, Error Loading relationship (goto1_gotomypc_accounts).

    Now I just need to know what the error loading it was I couldn't find any other related entries in the sugarcrm.log file. Any ideas on how I can find the problem with loading that relationship?

    Thanks again,
    Ryan

  4. #4
    ronB is offline Sugar Community Member
    Join Date
    Jan 2008
    Location
    Hamburg, Germany
    Posts
    12

    Default Re: Relate field and subpanel

    Hi Ryan,

    had the same problem when trying the tutorial as you did.

    Solution is quite simple:

    you used "Accounts" for the $dictionary array, but it has to be the singular of Accounts -> Account!... ran into the same trap. Don't really know if this is due to some typo somewhere or working as intended. If it is not a bug, I'd be happy if someone could point me to some Doc for this behavior - think I missed that while reading the Dev-Wiki.


    Regards, Ron

  5. #5
    dpatech is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    NC
    Posts
    287

    Default Re: Relate field and subpanel

    Change your relationship name in both places to be lower case to match the relationship name it is trying to load.
    - Sugar Team
    dpa Technology LLC
    e-mail: dpaDeveloper@dpatechnology.com
    web: http://www.dpatechnology.com

  6. #6
    ranthony is offline Member
    Join Date
    Dec 2007
    Posts
    9

    Default Re: Relate field and subpanel

    @RonB - I did see a cautionary note about case and spelling somewhere in my searches the other night. I tried changing Accounts to Account in the $dictionary name as you suggested but unfortunately that seemed to stop me from accessing the Accounts detail page at all. With Accounts there I can see the details, just not the subpanels. Perhaps that name is defined differently in our respective databases. I wish it were that though, cause then I'd be done!

    @dpatech - Good suggestion. I did try that just now, and it came with the same result and error log. That piqued my curiosity though, so I tried changing the capitalization in the 'get_subpanel_data' definition under the $layout_defs array and that controls the capitalization that is returned in that error message. So it would seem that it would be necessary for 'get_subpanel_data' to match the relationship spelling/capitalization, but unfortunately that didn't remove the problem either, but I suspect it got me closer to functioning subpanels! Any other ideas?

    Thanks for you suggestions!

    Ryan

  7. #7
    ztolley is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Re: Relate field and subpanel

    Any luck?

    It seems frustrating that something very simple like a one to many relationship and sub panel really should not be this hard.

    Need a simple step by step, how to link 1 item to another.

    I get error loading relationship and then gives my link field name. Should you put in the realtionship or link field name, and how can I debiug the loading of the relationship?

  8. #8
    dpatech is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    NC
    Posts
    287

    Default Re: Relate field and subpanel

    Make sure you are rebuilding the relationship cache after making any changes. This can be done via Admin->Repair->Rebuilt Relationships.
    - Sugar Team
    dpa Technology LLC
    e-mail: dpaDeveloper@dpatechnology.com
    web: http://www.dpatechnology.com

  9. #9
    ranthony is offline Member
    Join Date
    Dec 2007
    Posts
    9

    Default Re: Relate field and subpanel

    dpatech got to the bottom of this one after a little troubleshooting. The final trouble lay in the fact that I had named my relate field account. Apparently when doing one-to-many relationships using the relate field, Sugar expects to see these two fields, account_name and account_id (or replace account with the one side of that relationship). When you create the custom module and add the relate field, make sure you name it with the _name at the end of it.

    Thanks so much for your help dpatech!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. HOWTO - Hack Sugar to support related module info in subpanel (one-many)
    By kenneth.thorman in forum Developer Tutorials
    Replies: 35
    Last Post: 2008-06-10, 07:51 AM
  2. zero field value not shown in subpanel
    By johnfd in forum Help
    Replies: 0
    Last Post: 2007-09-28, 10:15 AM
  3. Replies: 2
    Last Post: 2006-07-30, 01:34 AM
  4. Subpanel field layout
    By skovron in forum Help
    Replies: 1
    Last Post: 2006-02-10, 01:37 AM
  5. how to add a custom link to a subpanel field
    By tooth_decay in forum Developer Help
    Replies: 3
    Last Post: 2005-12-06, 09:00 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
  •