Fetch data using an optimized query. Aggregates can load data from the server of the local database, and they support combining several Entities and advanced filtering.
We've been working on this article. Please let us know how useful this new version is by voting.
Client-side Aggregates run in the client logic. Use them to get data for your widgets when a Screen or a Block loads. Follow the steps:
Right-click a Screen or a Block and select Fetch data from Database. An empty Aggregate opens, and Service Studio shows that you need to add an Entity.
With the Aggregate still open, navigate to Data > Entities > Database.
Drag one of the Entities to the Aggregate window. Service Studio populates the Aggregate with columns that correspond to the attributes of the Entity. Note also the name change; if your Entity is MyEntity, the Aggregate gets the name GetMyEntity.
Go back to your Screen or Block and set an element to use the data. For example, if you have a List widget, set the Source of the List widget to GetMyEntity.List. You can always double-click an Aggregate to add more Entities, join data, or create filters.
Aggregates that run in the server-side logic are in the logic flows. To add an Aggregate in the server logic, drag an Aggregate from the toolbox to the flow of an action.
Fetching all records in client-side logic
There are cases when you always need to fetch all records from the database, for example to populate drop-down box lists. There are two ways of doing it:
- Use a Screen Aggregate and set Max. Records higher than the maximum number of records you expect. Keep in mind that large amounts of data may slow down the user interface and degrade the responsiveness of the app.
- Use a Data Action instead of Screen Aggregate and leave Max. Records field empty. In Data Actions, the Max. Records value is optional, and if you provide no value the Data Action fetches all records from the database.
Traditional Web Apps
In Traditional Web Apps, Aggregates run on the server, so you can only add server-side Aggregates.
To load data when the screen loads in Traditional Web Apps, place an Aggregate in the Preparation action (right-click a screen add select Add Preparation.). Preparation exists in Traditional Web Apps only.
|Name||Identifies an element in the scope where it is defined, like a screen, action, or module.||Yes|
|Description||Text that documents the element.||Useful for documentation purpose.
The maximum size of this property is 2000 characters.
|Timeout||Maximum time in seconds to wait for the Aggregate to return data before triggering a Communication Exception. Overrides the default timeout defined on the module.||If there is no value specified in this property, the timeout corresponds to the "Default query timeout" parameter specified in the Platform Server Configuration Tool.
Property not available in client actions.
|Cache in Minutes||Maximum time content or results are stored in memory. When undefined, nothing is cached.||Property not available in client actions.|
|Max. Records||Maximum number of records read from the database.||In Traditional Web App only. If undefined, the default value is:
– In widgets: StartIndex + LineCount + 1;
– Exporting to Excel: No limit.
|Start Index||Index of the first List item to iterate. Can be an expression.||The expression used in this property (if present) is evaluated before the web screen preparation.|
|On After Fetch||Action executed after the aggregate fetches data from the data source.|
|List||Collection of records returned by the performed query.||Record List|
|Count||Number of records returned by the Count query.||Long Integer|
|IsDataFetched||True when data has been fetched from the database and is ready to be used.||Yes||Boolean|
|HasFetchError||True when there is an error during data fetch due to a server error or communication timeout.||Yes||Boolean|