Email Logic Hook - After save

Hello,

I would like to execute a specific code after an email is received. The code parses the email subject and do specific actions. I would like a more custom way than binding the email with a case from the subject ( [Case:XXX] to Case XXX)
However it seems that the hook is never executed.

I use sugar 7.7.2

I added those files and ran "Quick Repair and Rebuild".

./custom/Extension/modules/Emails/Ext/LogicHooks/test.php

<?php

   $hook_version = 1;

   $hook_array['after_save'][] = array(
      1,
      'Create case or add to case',
      'custom/modules/Emails/Emails_hook.php',
      'email_utils',
      'link_to_case'
);

./custom/modules/Emails/Emails_hook.php

<?php

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

   class email_utils
   {
      function link_to_case($bean, $event )
      {
         $GLOBALS['log']->debug('-- Link to case executed');

         // code goes here

      }

   }

?>

What am I doing wrong here ?

Thank you for your help

Parents
  • Hi Bastien,

    I have found two missing pieces in your logichook definition.
    1.Please initialize array variable $hook_array like below.
    2.Please initialize array variable $hook_array['before_save'] like below.

    Logichook definition will look like something below.

    <?php
    $hook_version = 1;
    $hook_array = Array();
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(
    1,
    'Store values',
    'custom/modules/<module>/My_Logic_Hooks.php',
    'My_Logic_Hooks',
    'before_save_method'
    );
  • Thank you for you help Ajay.
    I actually follow this documentation and there was no initialization: http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Architecture/Logic_Hooks/#Hooks_with… 

    I added those two lines as you advise me (using after_save instead of before_save) :
          $hook_array = array();
          $hook_array['after_save'] = array();

    After a "Quick Repair and Rebuild" and receiving an email on my configured address still nothing is happening. I don't see my debug message and I have got no php error.

  • I gave more details on what I want to achieve below if this can help.

Reply Children
No Data