FREE OutSystems Workshops - Build an OutSystems App in 1 hour | ENROLL NOW

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

Tech Bites - How to use Screen templates

How to use Screen templates

Did you know that the OutSystems Platform has tens of screen templates to help you quickly put together your apps? Let me show you how you can use them.

Tech Bites
Tech Bites - Set timers to delete records

Set timers to delete records

In this tech bite, we will demonstrate how to set timers to delete records and use an online store as an example.

Tech Bites
Tech Bites - How to import data from an excel file

How to import data from an excel file

In this video, we’ll show you how to upload and store data from an excel file.

Tech Bites