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

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

‍What’s new in OutSystems Developer Cloud

‍What’s new in OutSystems Developer Cloud

Have you heard about the OutSystems Developer Cloud and want to know more about what's new and what the big benefits are? Then this article is for you!

DevZone
Tech Bites - Should we validate form data on server-side?

Should we validate form data on server-side

When including forms in applications, developers often wonder if they need to re-validate data on the server side after having checked it on the client. Why go to the trouble of checking the data twice?

Tech Bites
The Top 5 Mistakes Handling Asynchronous Data In Outsystems Reactive Apps And How To Avoid Them

The Top 5 Mistakes Handling Asynchronous Data In Outsystems Reactive Apps

When developing an OutSystems reactive web app, you would expect to display data quickly, but it doesn't always happen. Do you know why? We'll explore the reasons and how to tackle them.

DevZone