AnsweredAssumed Answered

Cannot remove users from meeting in after_relationship_add logic hook

Question asked by Richard West on Mar 16, 2015
Latest reply on Mar 16, 2015 by Richard West
This is for  SugarCRM Professional, Version 7.5.0.1.

The code I put in the logic hook on the users module after_relationship_add was:
class users_hook_class {
function modify_meeting_invite(&$bean, $event, $arguments) {
if (isset($arguments['related_module']) && $arguments['related_module'] == 'Meetings' && isset($arguments['related_id']) && !empty($arguments['related_id'])) {
$meeting = BeanFactory::getBean($arguments['related_module'], $arguments['related_id']);          
$meeting->load_relationship('users');
foreach ($meeting->users->getBeans() as $user)
   {
   $meeting->users->delete($meeting->id, $user->id);
   $meeting->save();
}}
}}


In logic_hooks.php I put:

<?php
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

 $hook_version = 1; 
$hook_array = Array(); 
// position, file, function 

$hook_array['after_relationship_add'] = array();
$hook_array['after_relationship_add'][] = Array(1, 'Custom Logic', 'custom/modules/Users/users_hook_class.php','users_hook_class', 'modify_meeting_invite');



This is boilerplate code to remove every user - I was going to narrow it down further, however this didn't work. I've run other code in the logic hook and added breakpoints - the code definitely runs, and I can load the user id and the meeting id.

I've tried multiple variations (e.g. changing the code to $meeting->meetings_users rather than $meetings->users and changing the delete code to just    $meeting->users->delete($user->id);). Nothing appears to work.


What am I doing wrong?

Outcomes