SugarCRM - insert new record in relationship table

Dejan picture Dejan · Mar 4, 2013 · Viewed 7.2k times · Source

Hi I am testing and trying to insert a record in relationship table but without success. I am trying to enter new row in relationship table using logic hook when I do Save in Contacts module but instead of that I am getting blank index.php page. Where is the problem? thank you

 <?php

    include_once('modules/Contacts/ContactOpportunityRelationship.php');
    class User_hook {

        function insert()
        {
            $instance=new ContactOpportunityRelationship();
            $instance->$contact_id='96163e07-f55a-eb87-251f-513482e4a1da';
            $instance->$opportunity_id='c99178c5-fed5-7092-4a79-4e1da40a1eea';
            $instance->save();

        }
    }
    ?>

Answer

davidboris picture davidboris · Mar 5, 2013

The correct syntax should be

<?php
$contactId = '96163e07-f55a-eb87-251f-513482e4a1da';
$oppId = 'c99178c5-fed5-7092-4a79-4e1da40a1eea';
$oContact = BeanFactory::getBean('Contacts', $contactId);
$oContact->load_relationship('opportunities');
$oContact->opportunities->add($oppId);