Aggregate Does Not Fetch Updated Database

I have a question. I have a table of which I populate with records from an external database, linked to OutSystems in Traditional Web. I populate the table with records by populating a list variable with an aggregate in the preparation and using that list variable as the source for the table.

To refresh the table, I simply use another of the same aggregate and re-populate the list variable then ajax refresh the table in a screen action.

I have encountered a problem: When a user saves a new record in a table, I have a screen action to create a new record in the database and after that record is created, I use an aggregate then re-populate the list variable again followed by ajax refresh, to refresh the table in the same "save" screen action. I have found that the aggregate that I use after the "Create Record" server action does not include the new record that was created directly above the aggregate. The only way that I can get it to include the new record is by using a "Refresh Data" before I use the aggregate.

Is there another way to get the updated table from the database without "Refresh Data" (without use of API) ? I believe that the performance best practices advised against using preparation data inside screen actions. In a way, refreshing the preparation data can be interpreted as "using" the preparation data but I am not sure. The document is not worded precisely.

Can anyone assist? Thanks!

Rank: #515

Hi Justin,

You don't have to use a variable to populate your table. You can just use "<AggragateName>.List" instead. Nonetheless, after create the record, you will just need to "Refresh Data" and then "Ajax Refresh". 

You could see how to achieve this here: https://www.outsystems.com/training/lesson/1790/ajax-interactions

I think that when the best practices advised against using preparation data in screen actions, it means that you must avoid using all data from a record in a request. Some might think that sending all the data and preventing the server to make a new database request is a better choice. But, sending all the data from a record in the request will increment the viewstate size. With time, this could be worse than a simple database request.

"For instance, instead of using the tablerecord record data, use only the ID of the row and fetch the data from the database again is needed"


Hope it helps.

Best regards.

Rank: #287

Hi Justin

Use the "Refresh Data" action is the best way to get updated data from the existing data source.  It's not against any best practice rule.

Kind Regards