Tech Bites - How to run aggregates for each table row

< Back to Blog

In some situations, we need to show specific data in a table row or a list item that might not be directly related to the data we are using on the aggregate.

In our example, we work with products, names, prices, and shopping lists. We also know which products were bought and how many units.

Each table row represents one entry on the shopping list. Products can appear many times depending on who bought them. However, what if we want to flag the products purchased over one hundred units, no matter who bought them?

Can we go to the "get products by id" aggregate and get that information? Unlikely, since it'll probably affect the output unexpectedly.

Should we fetch that data using a "data action"? No, because we can't run a "data action" for each row!

Additionally, that flag shouldn't be placed directly in the table cell. 

Instead, we should create a new Block.

Right-click on the MainFlow, choose “Add Block”, and name it. This new block can then safely be placed inside the table cell without any issues arising later on that can affect the app's good functioning.

Next, let’s create the block’s input parameter to specify data for each block instance. Name it as "product Id", representing the product to be passed on from the aggregate.

On the block, right-click on “Fetch Data From Database” to create a new aggregate. 

Drag the Entity “Shopping List” and go to the Tab Filter on the top left-hand side.

 Click “Add Filter” and, on the filter Condition window, filter the Shopping list by "product id". 

Back at the main window, right-click on the attribute “Quantity” and get the "sum function" of all units.

Back in our Block, drag and drop an “if widget”.

Set the “If Condition” logic to fetch the Sum Quantity attribute we got in the previous step and compare it to one hundred.

 Finally, drag the flag icon to the true clause of the If the condition.

After publishing and running our app, we now see that we have two products: books and spoons. But only the books were bought more than one hundred times!

Turn Up Academy

Apply to our Turn Up Boot Camp

AND BECOME THE NEXT OUTSYSTEMS CERTIFIED DEVELOPER
(
Instructor
)

Latest Articles

How to handle timeouts in OutSystems

How to handle timeouts in OutSystems

Join our instructor and OutSystems Champion Cláudia for a step-by-step tutorial on how to troubleshoot timeout issues in the OutSystems platform.

DevZone
How to download Excel files in OutSystems

How to download Excel files in OutSystems

Learn how to download Excel files using the OutSystems platform in this simple tutorial!

DevZone
Mastering Email Integration with OutSystems: A Step-by-Step Guide

Mastering Email Integration with OutSystems

In OutSystems Reactive Web Applications, we can configure the Service Center and implement logic in the Service Studio to send emails to our peers or contacts. Follow this step-by-step guide to learn how to!

DevZone