668
Views
4
Comments
Solved
Can't find the start Index for an aggregate
Question

Hi I'm searching for the start index for my aggregate to do some pagination but I can't find it in the Properties ? Here is the Photo : 

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi @Mohamed Ali LAJNEF ,

the StartIndex property on aggregates only exists when it is a screen aggregate, not when it is an aggregate inside a server action (which a DataAction kind of is).

If you want to apply pagination with aggregates inside server actions, you'll have to write your own logic for it.

This article by @Kilian Hekhuis  is a good read.  

The article works on the premise of retrieving the full list in one go from the DataAction, I'm not always a fan of that when there is a lot of data to get.  

Alternatively, 

  • you run the aggregate with
    • Max. Records =  Screen.StartIndex + Screen.MaxRecords
  • after the aggregate you add a ForEach with 
    • StartIndex = Screen.StartIndex
    • Maximum Iterations = Screen.MaxRecords
    • Inside the iteration, you append the record to the DataAction output

With this approach, performance will only deteriorate as you go further to the later pages in your pagination, which I think your user should never have to do anyway.

Dorine

2023-01-26 16-03-24
Ana Agostinho

Hello Mohamed Ali LAJNEF, 
It seems that you didn't understand some basic stuff. No worries :) 

Check the following documentation steps and the following two videos :) It has examples of how to do it! If you follow the steps you will not have problems:

Best regards, 

Ana

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi @Mohamed Ali LAJNEF ,

the StartIndex property on aggregates only exists when it is a screen aggregate, not when it is an aggregate inside a server action (which a DataAction kind of is).

If you want to apply pagination with aggregates inside server actions, you'll have to write your own logic for it.

This article by @Kilian Hekhuis  is a good read.  

The article works on the premise of retrieving the full list in one go from the DataAction, I'm not always a fan of that when there is a lot of data to get.  

Alternatively, 

  • you run the aggregate with
    • Max. Records =  Screen.StartIndex + Screen.MaxRecords
  • after the aggregate you add a ForEach with 
    • StartIndex = Screen.StartIndex
    • Maximum Iterations = Screen.MaxRecords
    • Inside the iteration, you append the record to the DataAction output

With this approach, performance will only deteriorate as you go further to the later pages in your pagination, which I think your user should never have to do anyway.

Dorine

2022-10-10 12-36-34
Ross Jennings

An alternative solution would be to convert the aggregate to an advanced SQL, passing in StartIndex and MaxRecords as parameters, then append the following at the bottom to the SQL query:

    OFFSET @StartIndex ROWS

    FETCH NEXT @MaxRecords ROWS ONLY

This syntax is explained in detail in this tutorial.

This "high-code" approach may not be appropriate for everyone, but it avoids the potential performance impact of loading all data at once (as in Kilian Hekhuis's article).

2021-05-18 19-42-11
Gabriel Melo

Recently I had to implement a complex query and this was the best approach. Important to say that the ORDER BY clause is required in this case, as shown in the linked tutorial.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.