Why should I use a Structure as Source of an Aggregate if it doesn’t have any data?

< Back to Blog

I have been working with OutSystems for over a year, but I have trained new developers in the last 10. I can assure you I have never worked with a software development tool as powerful and as easy to learn as Outsystems… but…

But sometimes things get confusing, and that is where things get interesting :)

I think I know very well OutSystems training materials, I use them almost every day, and some slides I even know them by heart.

A few weeks ago, one trainee came to me and asked, “Why should I use structures in an aggregate if they don’t have any data inside?”

My answer was something like: “Can you?”

But in reality, you can also mark a Structure as a Source:

However, if the structure (1) doesn’t have any data, and (2) the columns don’t even appear in the preview, the question is: Why?

  1. Because it isn’t a source like others.
  2. Because it has no data to show in aggregate.

Yet, it can store temporary data in those attributes left by the structure, extra attributes that can be used in the User Interface.

Structures are handled as Sources in an Aggregate because they are useful for the Aggregate to generate the SQL query. The SQL query result will include some extra null columns, like in the example below:

SELECT TOP (32) NULL o0, NULL o1, NULL o2, NULL o3, [ENEVENT].[ID] o4, [ENEVENT].[NAME] o5, [ENEVENT].[LOCAL] o6, [ENEVENT].[DATE] o7, [ENEVENT].[EVENTTYPE] o8, [ENEVENTTYPE].[ID] o9, [ENEVENTTYPE].[DESCRIPTION] o10

FROM ([OUTSYSTEMS].DBO.[OSUSR_BHT_EVENT] [ENEVENT]

Left JOIN [OUTSYSTEMS].DBO.[OSUSR_BHT_EVENTTYPE] [ENEVENTTYPE] ON ([ENEVENT].[EVENTTYPE] = [ENEVENTTYPE].[ID]))

Using debug tools, you can see that at runtime, the aggregate now has 4 new “columns” containing default values.

Furthermore, those new fields can store data about particular rows in the list.

In the image above, you can see the usage of that boolean value to manipulate the color in an If widget. At this example, the two If widgets have the conditions: “EventTable.List.Current.CRUD.HasUpdated”, and, “EventTable.List.Current.CRUD.HasDeleted”, respectively.

To manipulate these values, you can use Check Boxes with the variable property set to "EventTable.List.Current.CRUD.HasUpdated” and “EventTable.List.Current.CRUD.HasDeleted”.

In the image below, you can see that if you select one Check Box, the value of that particular item on the list will change:

We must realize something… the items saved on that CRUD structure are just data saved on the widget list and are not persisted in the database. If you want to save or use that data in the future, you need to save it somewhere and remember that you don’t have an entity in the database for that. As soon as you refresh the screen, you will lose all that information.

Remember, learning OutSystems can be very rewarding. But it helps if you fall in love with the platform! The second you and OutSystems meet each other very intimately, you will understand its behavior.

Say hello to the future!

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