Results 1 to 8 of 8

Thread: Logic Hooks in custom module

  1. #1
    Rajesh Patel is offline Sugar Community Member
    Join Date
    Sep 2009
    Posts
    35

    Default Logic Hooks in custom module

    I am using sugarcrm5j release

    I have created custom module using module builder and want to insert logic hooks on that custom module. i have gone thru all the post in forums and read the documentation also but not able to apply logic hooks.

    when saving record in custom module i want to insert one more record in other table this event should occur in after_save.

    Pls help to implement login hooks in custom modules.

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Logic Hooks in custom module

    Consider installing the package editLogicHook.
    It is available on sugarforge.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    Rajesh Patel is offline Sugar Community Member
    Join Date
    Sep 2009
    Posts
    35

    Default Re: Logic Hooks in custom module

    I have install the custom logic hooks but it is not working, i have added the following code using the logic hooks

    The two files are created when "Create and Edit Logig Hooks" plugin is used they are saved in "sugar/custom/modules/CVN". here CVN is my module name which i have created using module builder.

    logic_hooks.php Code

    <?php
    $hook_version=1;
    $hook_array = Array();
    $hook_array['after_save'] = Array();
    $hook_array['after_save'] = Array(1,'save','custom/modules/CVN/save-after_save_mjvn.php','save_class','save_method');
    ?>

    save-after_save_mjvn.php Code

    <?php
    class save_class
    {
    function save_method(&$bean, $event, $arguments=null)
    {
    if ($event != 'after_save') return;
    // Insert your custom logic between these comments

    $sql = "insert into CVN_Details (CVNBookno, CVNno) values ('1','2')";
    $result = $bean->db->query($sql,true);

    // Insert your custom logic between these comments
    }
    }
    ?>

    How do i check whether logic hooks are trigger or not..
    I have read all the documents related to logic hooks but none was found helpful

    Please suggest...

  4. #4
    Join Date
    Feb 2009
    Posts
    11

    Default Re: Logic Hooks in custom module

    Hey!

    EditLogicHooks has a tricky problem. It doesn't assigns the module name with the key you created for yout custom module, and then he creates a diferent folder.

    Let's say you have created your custom module called Events with the key patel, then your module will have the custom folder patel_Events.

    The problem here is, when editLogicHooks deploys your logic file, it creates the folder custom/Events and NOT custom/patel_Events.

    I had that problem before, what you need to do is, after your first deploy copy the file logic_hooks.php inside the custom/Events folder to the custom/patel_Events.

    You just need to do that once per logic file you create.

    Regards

  5. #5
    Gyro.Gearless is offline Senior Member
    Join Date
    Apr 2009
    Posts
    47

    Default Re: Logic Hooks in custom module

    Quote Originally Posted by Rajesh Patel View Post
    I am using sugarcrm5j release

    I have created custom module using module builder and want to insert logic hooks on that custom module. i have gone thru all the post in forums and read the documentation also but not able to apply logic hooks.

    when saving record in custom module i want to insert one more record in other table this event should occur in after_save.

    Pls help to implement login hooks in custom modules.

    So when you have handcrafted a custom module, you might be better off by implementing your own bean class than fiddling with logic hooks

    Module builder creates two bean classes right away, one is meant for customizations.

    An initial guess would be to overwrite function save_relationship_changes() - perhaps have a look in SugarBean.php for further enlightenment...

    HTH
    Gyro

  6. #6
    mvngti is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    South Africa
    Posts
    510

    Default Re: Logic Hooks in custom module

    Quote Originally Posted by Gyro.Gearless View Post
    So when you have handcrafted a custom module, you might be better off by implementing your own bean class than fiddling with logic hooks

    Module builder creates two bean classes right away, one is meant for customizations.

    An initial guess would be to overwrite function save_relationship_changes() - perhaps have a look in SugarBean.php for further enlightenment...

    HTH
    Gyro
    Firstly I have fixed the bug lightningspirit mentions in my newest release of editLogicHooks (and I corrected the spelling :-)

    You are absolutely right though - in your own modules it is much better to customise the bean file <module>.php directly rather than using logic hooks.

    This can be done prior to deployment in custom/modulebiulder/builds/<package>/SugarModules/<module>/<module>.php

    You have to overwrite the save method to do before_save and after_save actions and the retrieve method for before/after_retrieve.

    PHP Code:
    function save($check_notify FALSE)
    {
       
    // before_save here

       
    parent::save($check_notify);

      
    // after_save here

    PS: Tx for the recommendation Andre.

    M
    --


    Marnus van Niekerk

    There are only 10 types of people in the world
    those who can read binary and those who don't

    Modules:
    CE Teams - Upgrade safe teams module for Community Edition
    FieldACL - Field Level Access Control for Community Edition
    EditLogicHooks - Create and edit Logic Hooks from the Admin GUI
    FlexibleChartDashlet - Display any data in a Dashlet Chart
    DocumentThumbnails - Thumbnails for Documents module

    Many questions can be answered by reading the Developers Manual

  7. #7
    Join Date
    Feb 2009
    Posts
    11

    Default Re: Logic Hooks in custom module

    Thanks for the recomendations. Perhaps, it can be a better choice to implement inside the bean.
    But, i'm just wondering, if i deploy the module again my changes will be erased or not?

  8. #8
    mvngti is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    South Africa
    Posts
    510

    Default Re: Logic Hooks in custom module

    Quote Originally Posted by lightningspirit View Post
    But, i'm just wondering, if i deploy the module again my changes will be erased or not?
    No, they will not. After publishing or deploying your modules the first time the module builder creates a folder
    custom/modulebuilder/builds/<package>/SugarModules/modules/<module>/ than contain the file
    custom/modulebuilder/builds/<package>/SugarModules/modules/<module>/<module>.php which is the bean file for your new module.

    The module builder creates that file only once and will never overwrite it again, specifically so that you can make customisations in there.

    M
    --


    Marnus van Niekerk

    There are only 10 types of people in the world
    those who can read binary and those who don't

    Modules:
    CE Teams - Upgrade safe teams module for Community Edition
    FieldACL - Field Level Access Control for Community Edition
    EditLogicHooks - Create and edit Logic Hooks from the Admin GUI
    FlexibleChartDashlet - Display any data in a Dashlet Chart
    DocumentThumbnails - Thumbnails for Documents module

    Many questions can be answered by reading the Developers Manual

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 2009-09-13, 11:28 PM
  2. Custom logic hooks
    By milescook in forum Developer Help
    Replies: 2
    Last Post: 2009-03-05, 04:03 PM
  3. How to use logic hooks with the module builder?
    By mmoench in forum Developer Help
    Replies: 3
    Last Post: 2009-01-21, 09:26 AM
  4. Custom Fields-do I need to use Logic Hooks??
    By ctaylor2410 in forum Developer Help
    Replies: 2
    Last Post: 2008-10-24, 08:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •