Results 1 to 5 of 5

Thread: Custom calculated field based on CustomAgingField.php from Sugar University

  1. #1
    Billwobo is offline Sugar Community Member
    Join Date
    Mar 2008
    Posts
    33

    Default Custom calculated field based on CustomAgingField.php from Sugar University

    I created this custom field to calculate an amount from a price & a Quantity. I based this process on this Tutorial, from Sugar University: http://developers.sugarcrm.com/tutor...AgingField.pdf


    So my custom vardef is :

    PHP Code:
      'amount' => 
      array (
        
    'required' => false,
        
    'name' => 'amount',
        
    'vname' => 'LBL_AMOUNT',
        
    'type' => 'float',
        
    'CustomCode' => 'array('name'=>'getAmount', 'returns'=>'html',         'include'=>'custom/CustomCode.php'),
        '
    len' => '6',
        '
    comment' => 'Calculated total amount',
        '
    massupdate' => 0,
        '
    comments' => '',
        '
    help' => '',
        '
    duplicate_merge' => 'enabled',
        '
    duplicate_merge_dom_value' => '1',
        '
    audited' => 1,
        '
    reportable' => 0,
        '
    len' => '18',
        '
    precision' => '4,
      ), 
    It includes a custom file called custom/CustomCode.php.

    The Customcode.php file is:

    PHP Code:
    function getAmount($bean,$field,$value) {

    $price=($bean->price);
    $quantity=($bean->quantity);
    $amount = ($quantity $price);
    //
    return ($amount); 
    First of all the Amount doesn't appear in the "Amount" field, but rather at the top of the page, below the header.

    Then, although it does display an amount, the result is wrong.

    I know it's probably basic, but can anyone comment on this code? It would greatly help me comprehend php better.

  2. #2
    chad.hutchins is offline Sugar Community Member
    Join Date
    May 2007
    Location
    Texas
    Posts
    141

    Default Re: Custom calculated field based on CustomAgingField.php from Sugar University

    In your vardefs.php code, try changing 'CustomCode' to 'function'.

  3. #3
    Billwobo is offline Sugar Community Member
    Join Date
    Mar 2008
    Posts
    33

    Cool Re: Custom calculated field based on CustomAgingField.php from Sugar University

    Yeah, you're right about the 'function'. I forgot, that I had tried 'customCode' and forgot to change it. I fixed it.

    But it didn't do the trick.

    When I put only $price, or $quantity in the $amount() it gives me the right answer. It seems to be the a * b function that doesn't work.

  4. #4
    chad.hutchins is offline Sugar Community Member
    Join Date
    May 2007
    Location
    Texas
    Posts
    141

    Default Re: Custom calculated field based on CustomAgingField.php from Sugar University

    Hmm... What if you tried casting the variables to floats first? They might be returning as strings, so it is multiplying the two strings rather than the actual float values?

    PHP Code:
    $price = (float) $bean->price;
    $quantity= (float) $bean->quantity;
    $amount $quantity $price

  5. #5
    sidh211 is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    126

    Default Re: Custom calculated field based on CustomAgingField.php from Sugar University

    Hi,

    I tried this solution its working fine. But is it possible to store this calculated filed into database.
    I have crested column but null value is getting stored there. pls help.

    Thanks & Regards
    Sid

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. HELP - Act import (field mapping)
    By smelamed in forum Help
    Replies: 32
    Last Post: 2010-12-15, 05:39 PM
  2. Add a custom field to a formbase, like ContactFormBase
    By Barlow in forum Developer Help
    Replies: 0
    Last Post: 2008-07-09, 08:44 PM
  3. Custom Field Problem (bug?)
    By zmao in forum Help
    Replies: 5
    Last Post: 2007-11-13, 05:57 PM
  4. upgraded to 4.5.1e, received "Metadata for table tracker does not exist"
    By sfgeorge in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2007-09-03, 02:24 PM
  5. Custom Field not showing up
    By uswcc in forum Help
    Replies: 4
    Last Post: 2007-05-16, 01:37 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
  •