Results 1 to 6 of 6

Thread: Formula field

  1. #1
    korazy is offline Sugar Community Member
    Join Date
    Feb 2007
    Posts
    25

    Question Formula field

    Is it possible to create a custom formula field in sugarcrm? In the bugs module, we would like to add 5 custom editable numeric fields. In view mode, show a calculated score based on those 5 values.

  2. #2
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    1,539

    Default Re: Formula field

    It is possible, but needs some coding (in CE). In payed editions you can use "SugarLogic" for this (define a calculated field via configuration in admin->studio).
    Last edited by sts; 2013-01-16 at 01:43 PM.
    Stefan Ulrich Sauer
    System Analyst

    Devoteam GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.com
    http://www.devoteam.de

  3. #3
    korazy is offline Sugar Community Member
    Join Date
    Feb 2007
    Posts
    25

    Default Re: Formula field

    Can you direct me to some information or samples on programming that? We have basic experience with PHP so we can figure it out, but it will be slow.

    Basically what I want to do is using the Bugs module, add 6 custom fields that store integer values. 5 will be editable by users, the 6th will be calculated from the other 5 values. Total calculated value will be a formula from the other 5, not just a sum total.

  4. #4
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    1,539

    Default Re: Formula field

    First you create these fields via admin->Studio and place 5 unto Edit View and the sixth (or all) unto Detail View.
    Programming:
    You'll have to add a logic hook in your Bugs' module (before_save) and here you do the calculation (set the value of the sixth field using the values of the other 5).
    I've found a nice coding example here which does some calculation in a logic hook:

    custom/modules/<modulename>/process.php:
    PHP Code:
    <?php
     
    // prevents directly accessing this file from a web browser
    if(! defined('sugarEntry') || ! sugarEntry)
      die(
    'Not A Valid Entry Point');
     
    class 
    Process
    {
     
      function 
    process(&$bean$event)
      {
        
    // calculate item profit
        
    $bean->t_profit_c = ($bean->t_sale_price_c $bean->t_item_cost_c);
     
        
    // calculate sale profit
        
    if(!empty($bean->t_qty_sold_c))
        {
          
    $bean->t_sale_profit_c = ($bean->t_qty_sold_c $bean->t_profit_c);
        }
      }
     
    }
     
    ?>

    custom/modules/<modulename>/logic_hooks.php:
    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();
    $hook_array['before_save'][] = Array(1'process''custom/modules/<modulename>/process.php''Process''Process');
     
    ?>
    I hope this helps.
    Stefan Ulrich Sauer
    System Analyst

    Devoteam GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.com
    http://www.devoteam.de

  5. #5
    korazy is offline Sugar Community Member
    Join Date
    Feb 2007
    Posts
    25

    Default Re: Formula field

    Thank you. Works perfect.

  6. #6
    tabestmaker Guest

    Default Re: Formula field

    Thanks Sir I too Have That Poblem i was gonna post new topic but since i saw this one there is no need now

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Calculated Field Formula
    By tgk in forum General Discussion
    Replies: 2
    Last Post: 2012-08-20, 03:30 PM
  2. Replies: 2
    Last Post: 2012-06-15, 12:33 AM
  3. Help with dependent field formula in 6.2
    By shaneoston in forum Developer Help
    Replies: 10
    Last Post: 2011-12-16, 03:47 AM
  4. New field calculated formula
    By crowej in forum Developer Help
    Replies: 1
    Last Post: 2011-06-05, 09:10 PM
  5. add a formula type field
    By thinktodo in forum Feature Requests
    Replies: 1
    Last Post: 2009-06-19, 12:05 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
  •