Results 1 to 3 of 3

Thread: how to add a computing field

  1. #1
    jeysipi is offline Member
    Join Date
    Mar 2007
    Posts
    8

    Default how to add a computing field

    Hi! I just want to know how can I add a computing field that will total the value of the custom fields I made in a single or multiple records. Im using the community version of Sugarcrm version 5.2.0j. Thank you in advance.

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: how to add a computing field

    You'd create a read-only custom field and run a before_save logic hook to set the field to the sum of your custom fields. Should be plenty of examples on the forums here.

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

    Default Re: how to add a computing field

    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

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 20
    Last Post: 2010-09-27, 09:56 AM
  2. Replies: 3
    Last Post: 2010-02-09, 05:45 AM
  3. Replies: 0
    Last Post: 2010-01-14, 02:56 PM
  4. Replies: 4
    Last Post: 2009-02-23, 12:45 PM
  5. Replies: 2
    Last Post: 2008-11-18, 02:40 PM

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
  •