Displaying Computed Columns in OutSystems Lists Using Expressions from Aggregates
OutSystems is a powerful low-code platform that enables developers to swiftly create and deploy applications. One common requirement in applications is the need to display computed columns in lists, leveraging the data from aggregates. This guide will provide you with a detailed, step-by-step process on how to achieve this within the OutSystems environment.
Prerequisites
- Basic familiarity with the OutSystems platform and its development environment, Service Studio.
- An understanding of aggregates and how they are used to fetch data in OutSystems.
- Have an existing OutSystems Reactive or Traditional Web Application set up.
- Basic knowledge of expressions and how to use them in OutSystems.
Understanding Computed Columns in OutSystems
- Computed columns are custom columns that are not directly retrieved from the database but are calculated at runtime using expressions.
- They can be used to perform operations such as mathematical calculations, concatenation, or other logic based on data retrieved from aggregates.
Setting Up Your Aggregate
- Open your OutSystems application in Service Studio.
- Create or navigate to the Screen or Web Block where you wish to display your list.
- Drag and drop an Aggregate from the Data tab onto your canvas to fetch the necessary data.
- Configure your Aggregate by selecting the entities and attributes you need for your list.
- Ensure you have the necessary attributes that will be used to compute your new column.
Creating a Computed Column in the Aggregate
- Within your configured Aggregate, click on the "Add" button next to the "Calculated Attributes" section.
- Provide a name for your computed column that clearly describes its purpose (e.g., TotalPrice).
- In the expression editor, enter the expression that will compute the value for this column. For example:
<pre>
GetOrders.Total \* GetOrders.UnitPrice
</pre>
<li>Make use of operators and functions available in OutSystems to create complex expressions if needed.</li>
Displaying Your Computed Column in a List
- On the same Screen or Web Block, create a List widget or Table Records to display your data.
- Bind the List widget or Table Records to the Aggregate you have configured.
- Add a new Column or List Item to accommodate your computed column.
- Drag an Expression widget into the new Column or List Item.
- Set the Expression's value property to the computed column you created in the Aggregate. For instance:
<pre>
TableRecords1.List.Current.<AggregateName>.<ComputedColumnName>
</pre>
<li>Adjust the styling and formatting of the Expression as per your needs to ensure it displays correctly.</li>
Testing Your Computed Column Display
- Run your application by clicking the "1-Click Publish" button in Service Studio to ensure all changes are compiled and deployed.
- Navigate to the relevant screen in your application where the list is displayed.
- Verify that the computed column appears correctly within the List or Table Records with accurate computed results.
- Check that all edge cases such as null values, zeros, or unexpected data entries are handled appropriately.
Troubleshooting Common Issues
- Incorrect Calculations: Double-check your expression logic in the Aggregate and ensure all relevant fields are included in the calculation.
- Display Formatting Issues: Use the Expression Format tab in Service Studio to apply appropriate data formats for numbers or dates.
- Performance Concerns: Optimize complex expressions to ensure they do not significantly impact application performance during data fetch and display.
By following these steps, you can successfully display computed columns using expressions from aggregates in your OutSystems lists. This approach enhances data presentation by providing additional insights directly derived from existing database attributes, facilitating better user interaction and comprehension of information within your application.