Mastering Data Modeling with Liferay Objects

Course Overview

Transforming Data with Calculated Fields

Calculated fields offer dynamic, read-only values based on other fields. They are helpful for summarizing or calculating metrics directly from object data. By using calculated fields, you can take your application beyond user input to actionable, dynamic insights.

Liferay supports the following types of calculated fields for objects:

Field Type Description
Aggregation Calculate read-only values from a relationship table. Available functions include count, sum, average, min, and max.
Auto-Increment Store read-only values that increment for each newly created entry. You can set prefixes and suffixes that remain constant for each entry (e.g., APP-1, APP-2, APP-3).
Formula Calculate read-only values using numeric fields in the object definition.

 

Using Aggregation Fields

Aggregation fields calculate summaries of related object data to provide quick insights. They're read-only and dynamically updated. These fields require a one-to-many or many-to-many relationship between the objects in your application. In addition, the objects must have numeric fields to supply data to sum, average, min, or max functions. In a ticketing system, for example, aggregation fields on a ticket object can count total responses, sum total hours spent, calculate average response time, or show shortest and longest response times.

You can apply filters to aggregation fields to narrow down the entries used in the calculation and ensure only the most relevant data is included. For instance, you can filter by date to track the sum of claims submitted in a specific year. However, while you can add multiple filters, be cautious of overly complex filter combinations. Too many filters or conflicting criteria can exclude valuable data from the aggregation.

Using Auto-Increment Fields

Auto-Increment fields are useful for generating unique, human-readable identifiers that automatically increment for each new object entry. Using a prefix or suffix can help make the auto-generated value more meaningful and easily identifiable in the context of your application. For example, "INV-001" for invoices or "TICKET-1001" for support tickets can make the object’s function clear at a glance. Consistent naming schemes also enable more seamless API integrations. Try to choose a starting value that fits the scale of your project. For example, if your data model might scale to large numbers, start from a higher initial value. If you're using the field for internal tracking, starting from "1" may be sufficient.

When importing entries from external systems, ensure the auto-increment values do not conflict with existing entries. Overlapping values can lead to import failures or data inconsistencies. It's also important to maintain unique External Reference Codes (ERCs) alongside unique auto-increment values to ensure successful imports. Once you deploy and begin using an auto-increment field, avoid altering its format (prefix, suffix, or starting value), as this can cause inconsistencies in how new values are generated and recognized.

Using Formula Fields

Formula fields allow you to calculate real-time, read-only values based on other numeric fields within a single object entry. This is particularly useful for creating dynamic metrics such as totals, differences, or ratios directly related to the data within that specific entry.

You can use the standard arithmetic functions: addition (+), subtraction (-), multiplication (*), and division (/). These functions allow you to perform various operations, such as calculating response times, cost estimates, or totals from multiple fields.

Formula fields support both integer and decimal values. Depending on your use case, you can define whether the output should be an integer (e.g., the number of follow-ups) or a decimal (e.g., hours spent, calculated to a fraction of an hour).

Conclusion

Calculated fields help to transform your data models from flat user input forms to dynamic, insight-driven applications. By understanding when and how to employ calculated fields, you can make your object data work for you, instead of the other way around. Next, you’ll add some custom fields to Clarity’s distributor management app.

  • Using Aggregation Fields

  • Using Auto-Increment Fields

  • Using Formula Fields

  • Conclusion

Loading Knowledge

Capabilities

Product

Education

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy