Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Auto Calculate Math in Fields and Auto Fill from existing data

  1. #1
    infamousse is offline Senior Member
    Join Date
    Mar 2009
    Posts
    21

    Question Auto Calculate Math in Fields and Auto Fill from existing data

    So I am trying to accomplish two things at the moment, the first being simple math from two or more fields:

    i.e.: Field1, Field2, Field3, Field4
    Field4=Field1+Field2+Field3
    Is the general necessity of the work I am trying to accomplish, I am sure there is a trivial way to accomplish this but am not too familiar with customizing the fields to calculate based on the data inserted into the appropriate fields.
    Can this be done at the end of field submission or can it calculate during the data entry part of field input (prior to submission/save).

    The second item I am trying to do is replicate data from existing fields into other modules. For instance the cases module should carry over address, phone numbers, first and last names along with some custom fields I will be adding, how do I make the custom fields carry over the data from their respective counter parts?? Any and all advice would be a big help thanks.

  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: Auto Calculate Math in Fields and Auto Fill from existing data

    Quote Originally Posted by infamousse View Post
    i.e.: Field1, Field2, Field3, Field4
    Field4=Field1+Field2+Field3
    Is the general necessity of the work I am trying to accomplish, I am sure there is a trivial way to accomplish this but am not too familiar with customizing the fields to calculate based on the data inserted into the appropriate fields.
    Can this be done at the end of field submission or can it calculate during the data entry part of field input (prior to submission/save).
    To do that at the end of the submission you need to create a logic_hook before_save on module and perform the calculation inside logic_hook function.
    To do that during data entry you need to create customCode for the fields Field1, Field2 and Field3. This customCode should set a javascript event which will invoke a javascript function which will sum all fields and update the Field4 with the appropriate value.

    Quote Originally Posted by infamousse View Post
    The second item I am trying to do is replicate data from existing fields into other modules. For instance the cases module should carry over address, phone numbers, first and last names along with some custom fields I will be adding, how do I make the custom fields carry over the data from their respective counter parts?? Any and all advice would be a big help thanks.
    Please, clarify this last requirement. Give us a step by step work flow.

    Cheers
    Last edited by andopes; 2009-07-14 at 01:32 AM.
    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
    infamousse is offline Senior Member
    Join Date
    Mar 2009
    Posts
    21

    Default Re: Auto Calculate Math in Fields and Auto Fill from existing data

    Either option would work im sure, I am looking for the most trivial of the two. The custom form is basically just adding currency fields. For instance fields in the deposit section of the custom form will help me track payments via payment amount(s). So for that I have added payment1, payment2, payment3, and so on. What I want to do is add payments1-3 to total up at either submission/save or at payment1-3 input.

    This should store and reflect in either the edit mode or in the view mode, preferrably the view mode which will also be the printable option. Does this help clarify? Thanks for your response.


    Oh are there tutorials or has someone written this up for intermediate user's to view/ work off of? Again, many thanks.

  4. #4
    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: Auto Calculate Math in Fields and Auto Fill from existing data

    The most trivial one is the non javascript one, I mean, the one with logic_hook.
    There are some threads explaining how to do that.

    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.

  5. #5
    infamousse is offline Senior Member
    Join Date
    Mar 2009
    Posts
    21

    Default Re: Auto Calculate Math in Fields and Auto Fill from existing data

    Can you please link me the threads explaining the logic hook calculator? Looking through searches has brought up nothing of use. Maybe I am searching wrong.

  6. #6
    dorita234 is offline Junior Member
    Join Date
    Jul 2009
    Posts
    1

    Default Re: Auto Calculate Math in Fields and Auto Fill from existing data

    me too, I need more detailed info
    Data Entry

  7. #7
    infamousse is offline Senior Member
    Join Date
    Mar 2009
    Posts
    21

    Default Re: Auto Calculate Math in Fields and Auto Fill from existing data

    This seems to be something of a necessity I wonder why this was not implemented into the module and fields sections of the admin panel. Would be a useful tool for just about everyone. Well going to continue my search for an answer that suits me.

  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: Auto Calculate Math in Fields and Auto Fill from existing data

    Quote Originally Posted by infamousse View Post
    This seems to be something of a necessity I wonder why this was not implemented into the module and fields sections of the admin panel. Would be a useful tool for just about everyone. Well going to continue my search for an answer that suits me.
    This is one of the features targeted to version 6.0.

    The sample logic hook to accomplish this feature:
    custom/modules/Opportunities/logic_hooks.php
    PHP Code:
    <?php
    $hook_version 
    1;
    $hook_array = Array();
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1'calculate_field''custom/modules/Opportunities/OpportunityLogicHook.php','OpportunityLogicHook''calculate_field');
    ?>
    custom/modules/Opportunities/OpportunityLogicHook.php
    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    OpportunityLogicHook {
        function 
    calculate_field(&$focus$event$arguments) {
            
    // andopes comment: for float numbers it is necessary to unformat them to avoid wrong calculation
            
    require_once('modules/Currencies/Currency.php');

            
    $field1 unformat_number($focus->field1);
            
    $field2 unformat_number($focus->field2);
            
    $field3 unformat_number($focus->field3);
            
    $field4 $field1 $field2 $field3;
            
    $focus->field4 format_number($field4);
        }
    }
    ?>
    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.

  9. #9
    lassociates is offline Sugar Community Member
    Join Date
    Jan 2008
    Posts
    10

    Default Re: Auto Calculate Math in Fields and Auto Fill from existing data

    I did exactly this, the only problem is if the calculation is over 999.99 it enters a NULL value. Is there something that I am missing to be able to calculate over 999.99?

  10. #10
    Krissy-D is offline Sugar Community Member
    Join Date
    Jan 2011
    Posts
    41

    Default Re: Auto Calculate Math in Fields and Auto Fill from existing data

    Quote Originally Posted by lassociates View Post
    I did exactly this, the only problem is if the calculation is over 999.99 it enters a NULL value. Is there something that I am missing to be able to calculate over 999.99?
    I get the same problem, if the result = 999.99 or over then it won't display in editview or detail view... is there a workaround for this?

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Auto-fill relate field on custom module?
    By leowolff in forum Help
    Replies: 6
    Last Post: 2012-03-15, 02:06 PM
  2. Auto-fill field with filtering
    By prajeesh in forum Help
    Replies: 1
    Last Post: 2009-07-06, 01:38 PM
  3. Replies: 2
    Last Post: 2008-02-11, 05:15 AM
  4. Auto Calculate & Populate Fields
    By coowboy in forum Developer Help
    Replies: 2
    Last Post: 2006-06-26, 11:58 AM
  5. Outbound email auto fill function a bit funky
    By psdavec in forum General Discussion
    Replies: 0
    Last Post: 2006-04-07, 11:44 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
  •