Is it possible to create a global after_save logic hook?

I need to create an after_save logic hook that will run on all or a list of modules (array of module names to check) when a record in any of them is saved.

Instead of copying and pasting logic hook definitions to each and every module, is there a way to create such a hook globally? What kind of files should I put where?

I understand that global logic hooks are placed in ./custom/modules/logic_hooks.php, but is there any way to trigger a global logic hook on the save actions of any module?

I can see that an after_save logic hook in that logic_hooks.php file does work, but it does not seem right for my situation since in my log I can see that it triggers several times on a simple page load.
Is this because SugarCRM is based on modules and making a global after_save logic hook makes it trigger on many underlying system modules that are not even touched by the user directly?

I wonder if it would cause performance implications if I simply had a condition that allows the hook to only continue if the module that triggers it is in a list of allowed modules.

Edit: Actually the problem I have now is that I am unable to log function arguments and whenever I try to Sugar tells me "there was an error while connecting to the server".

According to the documentation the after_save logic hook should have arugments $bean, $event and $arguments, but like I said - none of them can be logged and when it tries to log it the saving is actually completely prevented.

  • Hi Francesca,

    With all the respect, I wouldn't agree that we see things from different perspectives :)
    I have a developer background and was a developer, but switched to system consulting many years ago.

    Working with Sugar for more than 11 years, I know that Sugar Admins got used to finding answers to their Sugar questions about non-OOTB (or look like non-OOTB) functionality in the Community first and now in the DevClub - hoping to get some help from code gurus - and that perfectly works!

    That happens because experienced developers' services are in high demand all over the world and Sugar Admins have no other way but to try to solve their tasks in the forums

    Therefore I wouldn't agree with the assumption that those who ask questions here, even if they show code snippets, always wish to learn coding or developer's terminology - I would say they rather hope to solve their challenge - and do it fast than return to Sugar daily usage or administering.

    Being aware of what code can from my background, I show another perspective - the ability to use no-code tools and do that by themselves, increasing personal efficiency instead of diving into the code world.

    This is modern approach trending now (just google "no-code") and I strongly believe that modern CRM cannot be one that does not allow subscribers to achieve their unique customization goals with no coding.

    BTW, a flowchart above is a 62nd(!!)  no coding solution provided in response to the challenge articulated in the SugarClub 

    I hope these reasons for being active in the DevClub make sense.



    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • Hi Dmytro,

    Thanks for the subtle classification.

    I am a full-stack developer (for a little longer than 17 years).

    Main developic activities in
    PL SQL
    PHP
    Javascript
    Basic Java

    Databases: Oracle, MySql

    WebApplications
    CMS Drupal, October
    CRM Sugar
    Know how to HTML, CSS, JSON, XML, XSLT, some frameworks and much more.

    I have the rewarding task to optimize and extend a totally wrong set up SUGAR-CRM. I want to make everything Sugar compliant (not like our first provider).

    It looks like I'm not just a lazy developer, I just want to understand SUGAR better. Since I'm the only one in my company, I'm also teaching myself everything about SUGAR on my own, and therefore need the support of this forum. And no, I don't want to buy any additional tools.

    Thank you and best regards
    Rene

  • Hi Rene,

    I have no (and ever had any) doubts about anyone's experience here.
    I'm also confident that any no-code configuring tool, either it is an out-of-the-box Sugar Studio or a non-Sugar-made Logic Builder, is not for those experts who do write direct code professionally or as a hobby.

    As a Partner to Sugar, we also have a team of developers and software architects and I'm excited about the fact that the development community for the Sugar platform is strong and helpful as many years ago - when Sugar had a CE version that one we started with.

    However, these days Sugar offers a lot of functionality out-of-the-box, assuming that non-developers can solve CRM tasks with Sugar themselves - with configuring.

    In the case Sugar Admins happened to face tasks which solutions were able to developers only, including to the task to inherit team or assigned user, they deserve to know they can make a lot of configuring themselves - with no-code tools like Sugar Studio or Logic Builder, - even if they read the original question within another 4 years.

    I never asked anyone to buy smth here - instead, I apply my team's experience in configuring to the tasks articulated in the SugarClub - whenever it can help to any reader, regardless of the forum branch this question is posted to

    I'm sorry if the ready-to-use and free solution example in the forum makes any disturbance - I see reasons for sharing experience for the sake of acquiring new Sugar customers and keeping the current ones for Sugar, since they may find no-code approach available to Sugar as beneficial - when comparing CRM platforms capabilities

    I hope this makes sense,

    All the best,
    Dmytro


    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • Just to make you aware on the manifest you need to do something like this example below.

    <?php
    
    $installdefs = array(
       
      'logic_hooks' => array(
        
        // global logic hook
        array( 
          'module' => '',
          'hook' => 'before_save',
          'order' => 60,
          'description' => 'Do global work SON!',
          'file' => 'custom/modules/Contacts/test.php',
          'class' => 'Global_logic_hook_class',
          'function' => 'Global_logic_hook_method',
        ),
      ),    
    );
     

    Rodrigo Manara

    Sr. Developer