I’ve just recently been asked to add a logic hook to inbound emails, so that the emails could be used to be updated the associated contacts. I’m not going to provide the full details here but just a few hints.
Firstly when you set up Inbound Emails, you must make the mailbox a group mailbox, if you want to use logic hooks. Non group emails go to the table email_cache not emails.
Note also that it is the scheduled task that polls the email account for new emails, so you need to wait for it run, normally once a minute.
Also, inbound emails only get imported if they remain unread. Read emails are ignored. Once Sugar has imported them, they are set as read on the server.
To setup a logic hook, you need to do it on after_save on the Emails module.
Thats all, but I can provide source if you need it.
I haven’t worked with SugarCRM for a couple of years so thought I would build a logic hook to refresh my memory. This one really should really be built into Sugar as an option. I think it would be the preferred behaviour for most people.
When you reassign an Account, this logic also reassigns all the Accounts contacts as well. Makes total sense that this is what you would normally do.
Anyway, these are the steps. Note the file names are mentioned in the source
1. Create a file like this
$hook_version = 1;
$hook_array = Array();
$hook_array['after_save'] = Array();
$hook_array['after_save'] = Array(1, 'accountReassign', 'custom/modules/Accounts/AccountReassign.php', 'AccountReassign', 'reassignUsers');
2. And a class like this
public function reassignUsers($bean, $event, $arguments)
$GLOBALS['log']->debug("calling hook reassignUsers");
$user_id = $bean->assigned_user_id;
if($user_id <= 0) return;
$contacts = $bean->get_linked_beans('contacts', 'Contact');
foreach ($contacts as $contact)
$contact->assigned_user_id = $user_id;
3. Check that all directories and files are readable by Sugar
4. Quick Repair
5. Give it a try
I hope that helps someone.