Results 1 to 9 of 9

Thread: Logic Hooks - Before Save

  1. #1
    john.luat is offline Senior Member
    Join Date
    Sep 2008
    Posts
    30

    Default Logic Hooks - Before Save

    Hello Guys,

    I was wondering if there is a way to resolve this problem.

    I have created a logic hook in a custom module. The event is Before Save. What happens now is when the user clicks on the save button, (the Logic hook before save is triggered and it works fine) i query the database for the existence of a certain record in the database. If the record already exists, an alert box pops up and i redirect the user in the list view. But i want to change this behavior so that when a record exists, it will not redirect to the list view but instead redirect to the edit view and the POST values will be carried over.

    Thanks and more power!!

    WinXP
    SugarCRM Community Ed 5.2.0a
    IIS 6
    PHP 5

  2. #2
    dekleinemedia is offline A Prolific Poster
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    241

    Default Re: Logic Hooks - Before Save

    Quote Originally Posted by john.luat View Post
    Hello Guys,

    I was wondering if there is a way to resolve this problem.

    I have created a logic hook in a custom module. The event is Before Save. What happens now is when the user clicks on the save button, (the Logic hook before save is triggered and it works fine) i query the database for the existence of a certain record in the database. If the record already exists, an alert box pops up and i redirect the user in the list view. But i want to change this behavior so that when a record exists, it will not redirect to the list view but instead redirect to the edit view and the POST values will be carried over.

    Thanks and more power!!

    WinXP
    SugarCRM Community Ed 5.2.0a
    IIS 6
    PHP 5
    Hi,

    Can you tell how you created this logic hook? Some code would be very usefull.
    Thankss
    Kind regards,

    De Kleine Media


    SugarCRM CE v.5.2.0h
    Windows platform
    MySQL v.5.1
    phpMyAdmin - 2.11.2.2
    Apache Server v.2.0

  3. #3
    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 - Before Save

    Quote Originally Posted by john.luat View Post
    Hello Guys,

    I was wondering if there is a way to resolve this problem.

    I have created a logic hook in a custom module. The event is Before Save. What happens now is when the user clicks on the save button, (the Logic hook before save is triggered and it works fine) i query the database for the existence of a certain record in the database. If the record already exists, an alert box pops up and i redirect the user in the list view. But i want to change this behavior so that when a record exists, it will not redirect to the list view but instead redirect to the edit view and the POST values will be carried over.

    Thanks and more power!!

    WinXP
    SugarCRM Community Ed 5.2.0a
    IIS 6
    PHP 5
    Hi John

    You need to add a code like that:

    PHP Code:
    $obj loadBean('<ModuleName>');
    $obj->retrieve($focus->id);
    if(
    $obj->name != '') {
      
    $_REQUEST['return_action'] = 'EditView';
      
    $_REQUEST['return_record'] = $focus->id;

    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.

  4. #4
    pravin.agham is offline Senior Member
    Join Date
    Sep 2010
    Posts
    64

    Default Re: Logic Hooks - Before Save

    Hi,

    I have tried the code given by andopes in before save logic hook but It doesn't work.
    Can you give me another solution.

    Regards,
    Pravin

  5. #5
    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 - Before Save

    Can you attach your logic hook?

    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.

  6. #6
    pravin.agham is offline Senior Member
    Join Date
    Sep 2010
    Posts
    64

    Default Re: Logic Hooks - Before Save

    Here is my logic hook; called before save

    PHP Code:

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

    class 
    chkEnquiryNumber {
        function 
    enquiryNumber(&$focus$event$arguments) {
        global 
    $current_user;
        if(
    $focus->enquiry_number_c!="" && $_POST['record']=="")
        {     
    //your code: chk for enquiry number
               
    $query "SELECT id_c FROM leads_cstm WHERE enquiry_number_c = '{$focus->enquiry_number_c}'";
                
    $result $focus->db->query($querytrue);
            if(
    $focus->db->getRowCount($result) != 0
            {
            
    //record is alrady present.
            
    $obj loadBean('Leads');
            
    $obj->retrieve($focus->id);
            
    //if($obj->name != '') {
              
    $_REQUEST['return_action'] = 'EditView';
              
    $_REQUEST['return_record'] = $focus->id;
            
    //} 
            //return false;
            
    }
        }
    else {die(
    'in else');}
     }
    //function
    }//class 

  7. #7
    pravin.agham is offline Senior Member
    Join Date
    Sep 2010
    Posts
    64

    Default Re: Logic Hooks - Before Save

    Any solution???

  8. #8
    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 - Before Save

    Try to remove the $_REQUEST assignment and instead add the code:

    PHP Code:
    header("redirect: index.php?module=$module&action=$action&record=$record"); 
    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.

  9. #9
    cornel_miron86 is offline Junior Member
    Join Date
    Sep 2011
    Posts
    3

    Default Re: Logic Hooks - Before Save

    Hy,

    if I have a logic_hook.php with after_login event, and in another module that I am installing I need to add another event, after_ui_frame, but I need to have both of them, how can I do that? because I've tried rewriting the logic_hook.php file from manifest but when I'm trying to upload the new module, sugar is giving me an error:
    Issue with the manifest

    Scanning Package

    Installation failed!

    The package you are attempting to install does not conform to the policies established within the Sugar Open Cloud or by your system administrator.
    Sugar Open Cloud customers must obtain a new package from the package provider that addresses the issues described below.
    If you are running Sugar locally, you can relax your Module Loader restrictions to allow the package to be installed.

    The Sugar Open Cloud package loading policies are detailed in the SugarCRM Knowledge Base.
    The available restrictions and exceptions are detailed in the SugarCRM Developer Zone.

    File Issues
    Invalid usage of a function file_put_contents()

    Please help.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. logic hooks and sql
    By mahmoud07 in forum Developer Help
    Replies: 3
    Last Post: 2010-02-25, 04:29 PM
  2. Logic Hooks
    By kalaisugar in forum Developer Help
    Replies: 7
    Last Post: 2009-05-08, 07:55 PM
  3. Logic Hooks
    By marketadvantage in forum Developer Help
    Replies: 3
    Last Post: 2009-01-30, 03:09 PM
  4. Logic Hooks
    By Delos in forum Developer Help
    Replies: 0
    Last Post: 2008-10-17, 01:01 AM
  5. logic hooks
    By user1000 in forum Developer Help
    Replies: 3
    Last Post: 2008-05-06, 07:51 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
  •