AnsweredAssumed Answered

Access Related Record Through A Logic Hook

Question asked by community-support on Jan 13, 2014
Latest reply on Mar 11, 2014 by ericgrapengeter
I am having difficulty accessing a related field through a logic hook.  I have a custom module that has a many-to-one relationship with Accounts.  Module holds orders for an account.  It needs to take the order total and add it to a running total for all the other orders of that category for the account.  I have tried before_save and after_save on the custom module and can't seem to get the related account in order to fetch the rest of the orders.  Once I have the account, I assume the method is the same to get all the orders for that account.

I tried using the following that I found in another post as a way to access related records, but this doesn't work.


       function updateOrderTotals(&$bean, $event, $arguments)


          $rel_accounts = 'accounts';


          $list = array();


          foreach ($bean->accounts->getBeans() as $account) {

             $list[$account->id] = $account;




I am relatively new to writing logic hooks, I've only done a few simple ones.  This one has me stumped.  I looked at the SugarBean spec and didn't find anything.  I may have missed it.  I've searched pretty thoroughly and haven't come up with many examples on how to do this, and the couple I have found all looked like the above.

Sugar 6.7.3 Corporate, OnDemand is the environment I am in.  I am loading code through the module loader.