AnsweredAssumed Answered

Unable to  add invitees to meeting created from Logic Hook

Question asked by Madhav Shenoy on May 26, 2015
Latest reply on May 28, 2015 by Rolustech Rolustech
I'm trying to create a meeting when a Campaign is approved. And the meeting should be visible to all users in their calendar. I've been struggling trying to finish this. I'm able to create the meeting but I'm not able to add users to the meeting at all. There are still further complex scenarios like recurrence which I need to implement. But for now I'm just trying to concentrate on adding users to the meeting.

We use Sugar Version 7.2.2

Here's my code I'm doing this in an after_save logic hook
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class Calendar_hook
{
function InsertEntry($bean, $event, $arguments)  {    $GLOBALS['log']->Info('begin InsertEntry');    if($bean->status == "Approved")  {      $datearray = explode("-",$bean->start_date);            $dateendarray = explode("-",$bean->end_date);     $date_start = new DateTime();   $date_start->setDate($datearray[0],$datearray[1],$datearray[2]);   //$date_start->setTime($bean->hour_selected_c,$bean->minute_selected_c);   $date_start->setTime(14,45);   $date_end= new DateTime();   $date_end->setDate($datearray[0],$datearray[1],$datearray[2]);   $date_end->setTime(14,45);   $date_end->add(new DateInterval('PT15M'));   $Meeting = BeanFactory::newBean('Meetings');   $Meeting->duration_hours = 1;   $Meeting->name = $bean->name;      $Meeting->type = "Sugar";   $Meeting->load_relationship('campaigns_meetings_1');                $Meeting->campaigns_meetings_1->add($bean->id);             $Meeting->Description = $bean->termsandconditions_c;        $Meeting->Status = "Planned";        $Meeting->duration_minutes = 0;                     $Meeting->save();            $Meeting->db->query("UPDATE {$Meeting->table_name} SET assigned_user_id='{$GLOBALS['current_user']->id}',   date_start='{$date_start->format('Y-m-d H:i:s')}',date_end='{$date_end->format('Y-m-d H:i:s')}' WHERE id='{$Meeting->id}' ");   $GLOBALS['log']->Info('InsertEntry completed creating meeting');   $users = BeanFactory::newBean('Users');        $Meeting->load_relationship('users');        $fields = array('id','user_name');        $q = new SugarQuery();      $q->from($users);   $q->where()->equals('deleted',0);        $namearr = $users->fetchFromQuery($q,$fields);   foreach($namearr as $user)   {    $Meeting->users->add($user->id);     $GLOBALS['log']->Info('InsertEntry user added ->'.$user->user_name);   }            $Meeting->db->query("UPDATE meetings_users SET required = 1,accept_status='none' WHERE meeting_id='{$Meeting->id}'");                                    }     }  }             
      Any help/ pointers will be appreciated.

Outcomes