Results 1 to 3 of 3

Thread: Question Before_Save Logic Hook

  1. #1
    jlabuelo is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    426

    Default Question Before_Save Logic Hook

    Hi there

    Lets see if you can give me a hand here. I am trying to set up a before_save logic hook for one of my custom modules. Have followed the instructions in the wiki (I think correctly) but dont get the process to work.

    Let me explain you the situation, In my custom module, what I want to get is sugar to check, before the record is saved, if ,when two specific values, of two dropdown files, are selected to check if a third text value is null.

    If so an alert message should appear, and if not the record should be saved.

    To get this Ihave created a logic_hook.php file in custom/modules/Pacie_Pacientes/ whith this content


    PHP Code:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version.  This file will    
    // be automatically rebuilt in the future. 
    $hook_version 1
    $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'][] = Array(1'Pacientes''custom/modules/Pacie_Pacientes/Comprobaciones.php','Comprobaciones''Comprobaciones'); 



    ?>
    Then I have created a php field called Comprobaciones.php in also custom/modules/Pacie_Pacientes/ with this code

    PHP Code:
    <?PHP
    /********************************************************************************/
    /**
     * THIS CLASS IS FOR DEVELOPERS TO MAKE CUSTOMIZATIONS IN
     */
    class Comprobaciones {
            
        function 
    Comprobaciones(&$bean$event$arguments) {
                
    // This funtion will check for records with field "estado" with value "Terminado" and field "respuesta" has value "Positiva", then 
    // the field "coste_expediente" Cannot be null

    // if so the record will be saved correctly, if not an alert message should be shown.
    // 

            
    if($bean->estado == 'Terminado'){
                   if(
    $bean->respuesta == 'Positiva'){$bean->CheckCoste($bean$event);}
               
                
            }else  {
    parent::save($event);}
            
            
           
        }
        
        
    // CheckCoste will check if the field is null or not, if it is an alert message should be shown and the record //must not be saved
    //    
        
        
    function CheckCoste(&$bean$event){
              if(
    $bean->coste_expediente == '')
              {
              
    // Alert message
              
    alert("Coste field should not be empty, please add the right value before saving.");
              }
              else
              {
    parent::save($event);}
      }
        
        
    }
    ?>
    Could you please let me know why I dont get this logic hook to work??

    Thanks a lot
    Edit/Delete Message

  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: Question Before_Save Logic Hook

    Hi jlabuelo

    If you would like to alert some message before saving the record, so you should add some javascript on save button the way this javascript calls some php script thru syncrhonous ajax.

    Regards
    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
    jlabuelo is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    426

    Default Re: Question Before_Save Logic Hook

    Hi Andre

    Thanks for the help. I have created the JS function to be called and check if the rule to show the alert message is correct or not before saving. However could you point me to any explanation where says how I can add this JS code to the Save button on a custom module, and also if possible, how can I make the record not being saved if the condition occurs?.

    Thanks a lot

    PHP Code:
    function Check_Save() 

      var 
    resply document.getElementById('respuesta');
      var 
    resply_str resply.value;
      var 
    status_str document.getElementById('estado').value;
      var 
    coste_str document.getElementById('coste_expediente').value;
      
     
       if ((
    resply_str == 'Positiva') && (status_str=='Terminado'))
      {
       
        if ((
    coste_str='') || (coste_str='0'))
         {
           
    alert ('Atención no puede guardar un Expediente en estado TERMINADO con Coste de Expediente nulo!');
           
         }    
      }



    Also I would like to build a mail and send it with SugarCRM to the mail address of the user assigned to the record of this custom module, but just depending on a field value. I was thinking I could do this with the Before_save logic hook with this "field checking" any suggestions on how I can do this??

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Logic Hook question
    By marketadvantage in forum Developer Help
    Replies: 3
    Last Post: 2009-01-23, 01:44 PM
  2. Replies: 2
    Last Post: 2008-12-24, 12:25 PM
  3. Logic Hook Question for Login
    By swhitlow in forum Developer Help
    Replies: 5
    Last Post: 2008-11-18, 02:50 PM
  4. Logic Hook Question
    By dalty52 in forum Developer Help
    Replies: 3
    Last Post: 2007-04-30, 02:07 AM
  5. Logic Hook Question
    By swhitlow in forum Developer Help
    Replies: 1
    Last Post: 2006-06-04, 04:49 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
  •