SugarCRM SupportHelp ArticlesStudio and Module BuilderSugar LogicIntroduction to Calculated Fields

Introduction to Calculated Fields

Overview

Sugar Logic allows administrators to create business logic for field calculations without needing to write PHP code. You can give a field a dynamic value that is automatically updated based on a calculation you provide.

For more information on calculated values, please refer to the Studio documentation or read through an example in our Sugar Logic section of the Knowledge Base.

Features and Restrictions

Using calculated values in your deployment can help you get the most out of Sugar. You can automate redundancies, perform mathematical processes, copy data from other fields, and so much more. Calculations like these can help streamline your data entry, freeing up valuable time for your users to focus on their specialties, and ultimately contributing further to your success as a business.

Once you have made a calculated field, it is important to be aware of what to expect when that calculated value is first deployed in your instance.

Note: When creating a calculated formula for a Currency field, the currency symbol should not be used for a value (e.g. $100) in the formula. The formula should only define the numeric value (e.g. 100), as including the currency symbol will result in improper calculated values.

Updating Calculated Field Formulas

When adding a calculated field to a module, the calculated field will appear blank in all of the historical records in your system. The calculated value is not updated automatically when added to records that already existed in your system. Similarly, when modifying an existing calculated field's formula, the field will not automatically recalculate on all existing records in the module.

When the need arises to update calculated values in multiple records, each record can individually be edited and saved. However, this can be time-consuming and impractical for a large number of records. Administrators and users with developer-level access to the module can use the Recalculate Values option to update multiple records at once:

  1. Navigate to the module's list view and select those records you wish to update.
  2. From the Actions menu, choose Recalculate Values.

This will trigger a recalculation of all calculated fields in the selected records.

Note: List views will allow you to select up to 1000 records. If you desire to recalculate values for more than 1000 records, you will need to break the records into several batches.

Automatically Updating Calculated Values

Sometimes a calculated field is based on values of other modules. To keep a field which is pulling values from other modules updated, Sugar will automatically re-calculate these fields when a related record changes. If you have a large number of calculated fields depending on related modules, performance can be hindered for your users when editing and saving records.

For example, if your Agency Type field on the Contacts module is based on the related Account module's type, making an edit to the account record will automatically trigger the contact's Agency Type to be re-calculated.

If you or your Sugar partner has access to your instance's file system, this behavior can be disabled by adding the following to config_override.php: $sugar_config['disable_related_calc_fields'] = true;

What this parameter means is that the related field calculations will only be executed on explicit saves of a record containing the calculated field. In the above example, editing the account would have no bearing on the related contact with the calculated field, but saving the contact would update the field value.

As long as this value is set to 'false' or is not set, a save on one module will cause all related module's calculated fields to be updated automatically.

PatrickM

Last modified: 2020-01-30 19:12:57