AnsweredAssumed Answered

How to change Team on Email record with Logic Hook?

Question asked by Kristjan Geir Mathiesen on Dec 11, 2018
Latest reply on Dec 12, 2018 by Kristjan Geir Mathiesen

Hi folks.

 

I´ve got an Inbound email handler that creates Cases from emails. Trying to change the Teams on my Email record from the Administrator and salesdistro teams over to Global. This is the code but it´s not working, seem´s like the Logic Hook is never triggered:

 

In /custom/modules/Emails/Ext/LogicHooks I have the file EmailLogicHookCustom.ext.php:

<?php

$hook_version = 1;

$hook_array['after_save'][] = Array(1,'Change Team to
Global','custom/modules/Emails/EmailLogicHookCustom.php','EmLogicHookCustom','changeteam',);

?>

And then in /custom/modules/Emails is the file EmLogicHookCustom.php:

<?php

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class EmailsLogicHookCustom
{
function changeteam($bean, $event, $arguments)

{
$primary_team_id = '1';

//loop prevention check
if (!isset($bean->ignore_update_c) || $bean->ignore_update_c === false)
{

if($bean->load_relationship('teams')){
$bean->team_id = $primary_team_id;
$bean->teams->replace(array(
$primary_team_id
)
);
$bean->ignore_update_c = true;
}
}

}
}

Same kind of code is working just fine in changing the Team on Cases.

What am I missing here?

Are emails handled differently than other records?

 

Thanks so much,

KGM

P.s. Sugar 8.0.2

Outcomes