3

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();

        }
    }
    ?>
Veljko
  • 1,708
  • 12
  • 40
  • 80

1 Answers1

7

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);
davidboris
  • 196
  • 3
  • could you please maybe help me with this one? http://stackoverflow.com/questions/15254673/sugarcrm-how-to-get-popup-when-click-on-save-button I want to get some pop up when clicking Save (first with some message later I would like to add OK and Cancel options). Thank you in advance – Veljko Mar 06 '13 at 18:05
  • What if I dont know the value of oppID ? How do I get that ? – user3286692 Jun 21 '14 at 04:30
  • @davidboris what if I need to update a previously added relationship entry? – Atif May 10 '16 at 06:29