AnsweredAssumed Answered

new bean relationship fields don't save

Question asked by Tom Noel on Feb 27, 2018
Latest reply on Feb 27, 2018 by Tom Noel

I have an after_relationship_add logic hook that triggers when the Account on a Contact is changed.  The logic hook then fetches related "Trade Show Attendance" records and creates duplicates adding the Contact in the relationship field.


My problem is that while duplicating these records none of the relationship fields are saving.  My code below:

I'm developing in a vagrant 7.10+ environment and this Sugar instance is on 7.11.  My operating system is Mac OS version 10.13.3.  I was curious if this was an environment issue so I deployed to an ondemand sandbox and was still receiving the same issue.  Any help would be appreciated on how to properly set relationship fields on a newBean in a logic hook.

class contactAttendee
    function contactAttendee($bean, $event, $arguments)

        if($arguments['link'] == 'contacts'){

            $query = new SugarQuery();
            $accounts = $query->join('accounts_tsa_trade_show_attendance_1')->joinName();
            $results = $query->execute();


                foreach($results as $key => $tradeshowattendance){

                    //related Trade show attendance record
                    $ts_attendance = BeanFactory::getBean('TSA_Trade_Show_Attendance', $tradeshowattendance['id']);

                    $exclude = array(

                    $new_trade_show = BeanFactory::newBean('TSA_Trade_Show_Attendance');

                    //Trade Show relationship add
                    if ($new_trade_show->load_relationship('ts_trade_show_tsa_trade_show_attendance_1'))

                    //Contact relationship add
                    if ($new_trade_show->load_relationship('contacts_tsa_trade_show_attendance_1'))

                    //Account relationship add
                    if ($new_trade_show->load_relationship('accounts_tsa_trade_show_attendance_1'))

                    foreach($ts_attendance->field_defs as $def){
                            && !in_array($def['name'], $exclude)){
                            $field = $def['name'];
                            $new_trade_show->{$field} = $ts_attendance->{$field};






I've also tried setting the relationship field directly rather than using the add function like so:

$new_trade_show->accounts_tsa_trade_show_attendance_1accounts_ida = $ts_attendance->accounts_tsa_trade_show_attendance_1accounts_ida;



Tom Noel