I have created a module in suitecrm that would allow users to create or view nc case. When a nc case is created an email notification is sent to the person assigned to this variable $rev_email, however when the email is sent it is being duplicated in the person’s inbox when the admin should only be receiving it once.
/* Set Email Subject */
/* Get NC Case Number */
$case_number = $bean ->case_number;
$xtpl->assign('Case_Number', $case_number );
/* Get NC Subject */
/* Get Case Description */
/* Create email message using email template and data above */
$email->Body = from_html($xtpl->text('main'));
function send_notification($bean, $event, $arguments)
/*Get sugar email engine*/
$email = new SugarPHPMailer();
$email->From = 'firstname.lastname@example.org';
$rev_email = 'email@example.com';
/* Get sugar template engine */
$xtpl = new XTemplate("XTemplate/CasesEmailTemplate.html");
/*GEt the URL for the NC Case */
$url = $GLOBALS['sugar_config']['site_url'].'index.php?module=Cases&action=DetailView&record='.$bean->id;
$xtpl -> assign('URL', $url);
/* Get Case ID */
$id = $bean->getFieldValue('id');
$email=createCaseEmail($email,$rev_email,'New Case Email Notification',$bean,$xtpl);
/* Send email to Production Department */
$GLOBALS['log']->info("Could not send notification email: ". $email->ErrorInfo);
I asked “exactly” where did you put it, and you answered “logic hook” :unsure:
It’s likely your logic hook is getting called twice. There are many reasons why this could be happening, it would depend on which logic hook it is. It could be called once for the record creation, and once for the relationship creation.
Try to find the difference between the calls in the hook parameters, and add an “if” to make it run only on one of them.
Where exactly is that file defining the logic hook placed, please?
I think your logic hook routine should be in the “custom/Extension/modules/Cases/Ext/LogicHooks/cases_email_notification.php” directory, check that uppercase “Cases” and the extra dir level for “LogicHooks”.