Aggregate starting from row number

Aggregate starting from row number

  

I have an API I created in Outsystems that pulls an aggregate together from a few tables, and sends the resulting recordset out to be consumed by an external service.  However, the result list is pretty sizable, so we're trying to give the external service a paging functionality where it'll only have to deal with a few dozen records at a time.

I can easily give the aggregate a Max Records value to get back only the first 40 records, but then when I need the next set, I'm stuck.  How do I tell the aggregate to give me 40 records starting at record 41 (or 81, or 121), the way I can do with a Table Records widget?

Hi Ryan,

Aggregates don't support that pagination use case directly, which is why the Table Records widget has a Start Index property to accelerate that pattern.

In some cases, it is acceptable to paginate by something other than the row number:

  1. Your API could have a StartId parameter, and just get the first 40 records starting on that Id (with a filter). The external service would then check what is the last Id you sent, and make the next request with that Id. 
  2. Or maybe your records have some Date associated, and it is acceptable to paginate by time period using StartDate and EndDate parameters.

If that's not the case and you really want to paginate by row number, there are other options.

In general, if your bottleneck in terms of performance is the external service, you can build a list with just the items from the Aggregate's result that you want to send.

  • The Aggregate's MaxRecords would be something like StartRecord + 39, to get all records up to the last one we want to retrieve.
  • We would build a new list by appending the Aggregate's records between index StartRecord and StartRecord + 39 (inclusive). We can take advantage of ForEach's Start Index and Maximum Iterations properties to only go through those we want to append.

If your bottleneck is really the Aggregate fetching the records, then my suggestion is to use an Advanced Query for that specific pagination use case.

Regards,

Paulo Ferreira

Paulo Ferreira wrote:

  • We would build a new list by appending the Aggregate's records between index StartRecord and StartRecord + 39 (inclusive). We can take advantage of ForEach's Start Index and Maximum Iterations properties to only go through those we want to append.


Ah, thank you.  I hadn't noticed I could use ForEach that way.