AnsweredAssumed Answered

Get_linked_beans only retrieves one record

Question asked by tanphat911 tanphat911 on Apr 23, 2014
Latest reply on May 2, 2014 by paperless
Hi every body, 

i try to using logic hook to get all related Contact from my custom Opportunity module to Client Module . Any i got some problems on function get_linked_beans(). As i know if will take all related record but in my situation it on get one record instead. Here is my code
function updateCompanyRelated(&$bean, $event, $arguments) { 
   require_once('modules/Contacts/Contact.php');                   require_once('modules/SCP_Opportunity/SCP_Opportunity.php');

  if ($arguments['related_module'] =='SCP_Opportunity')
  {

  $opportunity = new SCP_Opportunity();
  $opportunity->retrieve($arguments['related_id']);
  //Get Relate company
  $bean->load_relationship('scp_stakeholder_scp_company');
  $bean->scp_stakeholder_scp_company->add($opportunity->scp_company_id_c);
  $bean->scp_stakeholder_scp_company->add($opportunity->company);
  //Get Relate Contacts
  $contacts = $opportunity->get_linked_beans('scp_opportunity_contacts','Contact');
  $bean->load_relationship('scp_stakeholder_contacts'); 
  foreach ($contacts as $contact) { 
  $bean->scp_stakeholder_contacts->add($contact->id);
    }
         }  
         $bean->save();
           }
       }






And here is the result



Outcomes