AnsweredAssumed Answered

Creating  notes results in infinite loop

Question asked by ananth ananth on Oct 16, 2014
Latest reply on Oct 16, 2014 by Alex Nassi
Hi 

When i try to create a notes using logic hook, it works fine in Edit or Create view in the notes module. But when i try to create the same notes in the Quick create view in the subpanel of the Cases module. It results in the infinite loop when it reaches the code ( $notes_bean->save() ) function in the following code. 

CODE : 

class Notenotifications {
function publicemail(&$bean, $event, $arguments)
{
global $db;
 
$id= $bean->id;
$parent_type = $bean->parent_type;
$public_desc = trim($bean->description_public_c); 
   $notify_dropdown = $bean->notify_public_note_c; 
 
     $db_parent_type = $bean->fetched_row['parent_type'];
   $db_public_desc = $bean->fetched_row['description_public_c'];
   $db_notify_dropdown = $bean->fetched_row['notify_public_note_c'];
 
   if($public_desc != ""){ 
$bean->public_note_c = '1'; 
}
else { 
$bean->public_note_c = '0';
}
//if($parent_type == "Cases" && $public_desc != "" && $notify_dropdown == "1"  && ( $parent_type != $db_parent_type ||  $public_desc != $db_public_desc || $notify_dropdown != $db_notify_dropdown ) )
if($parent_type == "Cases" && $public_desc != "" && $notify_dropdown == "1" )

$cases_id = $bean->parent_id; 
//$cases = BeanFactory::getBean('Cases')->retrieve_by_string_fields(array('id'=>$cases_id));
$cases = BeanFactory::getBean('Cases', $cases_id);
$cases->load_relationship('Cases'); 
$email = $cases->email_contact_case_c; 
$case_type = $cases->type;
$cases_parent_id = trim($cases->cases_cases_1cases_ida);
if($case_type == "i_tecnico_interno" && $cases_parent_id != "")
{
$notes_bean = BeanFactory::newBean("Notes");
 foreach($bean as $k =>  $v)
 {
  if(is_string($v) || is_numeric($v)){ 
  if($k == "id")
  { continue; 
  }
  elseif($k == "parent_id")
  {
   $v  = $cases_parent_id;
   $notes_bean->{$k} = $v;
  }
  else {
   $notes_bean->{$k} = $v;
  }
  }
 }
$notes_bean->save();   // when the flow reaches here it redirects to same function again and again . this is the problem. 
}
}
}
}
?>
                                                                                                                            

Any help would be greatly appreciated. 

Outcomes