AnsweredAssumed Answered

Error occurring after submitting new Note record for a Contact

Question asked by Muhammad Shaji Uddin on Jun 24, 2014
Dear,

I implemented logic hooks for Notes module that whenever a new Note will be create for a Contact then Teams of that Contact will be added to that new Notes Teams (from Contact detail view, Note sub panel)

Above logic is working fine but in end it shows (HTTP 500 Internal Server Error) and stops on Create form

logic hooks code is below

logic_hooks.php
---------------------
$hook_version = 1; $hook_array = Array(); 
// position, file, function 
$hook_array['after_save'] = Array(); 
$hook_array['after_save'][] = Array(1, 'add teams', 'custom/modules/Notes/addteams.php','addteams', 'addteams');

addteams.php
------------------
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
ob_flush();
require_once('modules/Teams/Team.php');
require_once('modules/Teams/TeamSet.php');

class addteams {

   function addteams(&$bean, $event, $arguments) {

       //variables
       global $db;

       if($arguments['isUpdate'] != 1 && $bean->parent_type == 'Contacts')
    {
    $contact_id = $bean->contact_id;
    $teams_ids = array();
    $team_obj = new Team();

       if(isset($bean->team_set_id)){ // If already team is set for the record.

        //Get Teams of Contact
        $ContactTeams = $db->query("select distinct B.team_id
         from contacts A inner join team_sets_teams B on A.team_set_id = B.team_set_id
         where A.id = '{$contact_id}' and A.deleted = 0 and B.deleted = 0");
        while ($query_row_teams=$db->fetchByAssoc($ContactTeams)) {
         $idd2 = $query_row_teams['team_id'];
         $teams_ids[]=$idd2;
          }
        }

      //200. Update Note TEAMS (existing teams and the default team
      $bean->load_relationship('teams');
      $teams_ids[]=$teams_ids;
      $bean->teams->replace($teams_ids);

       }

   }
   
}


Regards 

Outcomes