Results 1 to 7 of 7

Thread: Calculated fields 6.1?

  1. #1
    Meyer is offline Sugar Community Member
    Join Date
    Oct 2006
    Location
    south africa
    Posts
    646

    Default Calculated fields 6.1?

    Hi there

    How can i get something like this in calculated fields?

    concat(
    (if team = products then 'prod'
    else if team = sales then 'sale'),(left(opportunity.id,3),year(now),motnh(no w))

    thanks

    Paul

  2. #2
    rafael.q.g@hotmail.com's Avatar
    rafael.q.g@hotmail.com is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Florianópolis - Brazil
    Posts
    782

    Default Re: Calculated fields 6.1?

    You can use customCode into yout field on your edit/detail view to renderize it, or in your field vardefs, you can assign a function reponsible to diplay the field contents. This second case is very more flexible.
    Rafael Queiroz Gonçalves
    Advanced OMG UML Certified Professional
    Sun Certified Enterprise Architect for the Java Platform
    Sun Certified Programmer for the Java 2 Platform
    IBM Certified Advanced Application Developer - Lotus Notes and Domino
    IBM Certified Application Developer - IBM WebSphere Portlet Factory
    Computer Science Mastering / UFSC - PPGCC

  3. #3
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: Calculated fields 6.1?

    What to do depends:
    • What edition are you using? CE? Pro?
    • Do you want to show the calulated value only or do you want to store it in database?
    Stefan Ulrich Sauer
    System Analyst

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

  4. #4
    Meyer is offline Sugar Community Member
    Join Date
    Oct 2006
    Location
    south africa
    Posts
    646

    Default Re: Calculated fields 6.1?

    I am using pro - Should store to the database.

  5. #5
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: Calculated fields 6.1?

    In Pro you can use the Formula Builder with 6.1 for calculated fields.
    Some documentation can be found here:
    http://www.sugarcrm.com/crm/support/...n.html#1670624 (search for "Calculated Value Fields")
    http://www.sugarcrm.com/crm/support/...c.html#9000011

    I've tried to create a variable using your formula (in my 6.2 installation). Some parts are working fine, other methods are not avilable in the formula builder. For 'if A then B else C' you can use the method 'ifElse(A,B,C)', for 'A=B' this would be 'equal(A,B)'. There is a method monthofyear(<date>) that you could call 'monthofyear(now())'. For 'left' and getting year there seems to be no method available in the Formula Builder until now.
    Stefan Ulrich Sauer
    System Analyst

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

  6. #6
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: Calculated fields 6.1?

    What could you do instead?
    With 'before_save' logic hook you could do such a calculation and assign the result to the field.
    Here a simple example for the implementation:
    PHP Code:
    <?php
    class MyOpportunitiesLogicHooks{
        function 
    calculateProvisionEuro(& $bean$event$arguments) {
            
    $bean->provision_euro_c $bean->amount $bean->provision_prozent_c 100.0;
        }
    }
    ?>
    Stefan Ulrich Sauer
    System Analyst

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

  7. #7
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: Calculated fields 6.1?

    Found out how to add new methods to formula builder:

    1) Create new method implementation in directory custom\include\Expressions\Expression\<data type>. Copy an existing file from include\Expressions\Expression\<data type> and edit ... It is more or less self-explanatory. Please be aware that the php file contains a JavaScript implementation of the method too.

    2) Remove files in cache/Expressions

    3) Start Studio (this will force Sugar to re-create the files in cache/Expressions)
    Now the new method should be available for use in Formula Builder.
    Stefan Ulrich Sauer
    System Analyst

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

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Calculated Fields
    By alexbloom in forum Help
    Replies: 8
    Last Post: 2010-01-19, 07:31 PM
  2. Calculated Fields
    By cbeagle in forum Developer Help
    Replies: 7
    Last Post: 2009-10-15, 08:33 AM
  3. Calculated Sum of 2 fields
    By kinshibuya in forum Help
    Replies: 14
    Last Post: 2008-11-04, 07:32 PM
  4. Creating Fields - calculated fields and 'related' field
    By gipps in forum General Discussion
    Replies: 0
    Last Post: 2007-07-21, 10:17 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
  •