Order By function


Hello everybody, i have this table records, i want to add a dynamic sort to order by skill rating, my problem is, that skill rating is not an attribute from an entity , it is calculated for the expression 

GetPlayerAverageRating(PlayerTable.List.Current.Player.Id)

How can I define my list sort column widget for it work?

Please Answer Me


yes, the function is present on the aggregate but, for example, when we choose a column that is attribute from an entity, column name is just {entity}.[attribute]. when the column is a function, what is the column name??

Hi Gonçalo,

In this cases normally we try to do those averages on the aggregate with calculated attributes and than instead of using {entity}.[attribute] you just need to use the name of the calculated attribute. Order by a function that is calculated after the aggregate is returned you would need to implement that ordering by yourself using LIstSort. Just add to that column header a link to a screen action which orders the list with the ListSort action.

Regards,

Marcelo

Hi! 

The function 

GetPlayerAverageRating

Is probably not accepted inside the aggregate. 

Tray create a "local variable" that is list equal to the table in the screen,  populate the list with the aggregate and the formula as  you are doing in the screen , then use the "List Sort" action on that variable. 

Hope to help.

Graça

Hi Gonçalo,

1. You can use functions in expressions inside an aggregate, but only if the function can be used directly in the SQL generated (is a function the platform knows how to translate to SQL), or it can be solved before the aggregate is executed. This means that you can't pass an argument to a Server Action (defined by you) that is part of the SQL itself (like a row attribute). What you're doing is to pass an ID of the Current record of the list of the Table/List Records in the screen, and it won't change for each line, meaning the system is able to run the action ONCE before the aggregate is executed and use the same result value on each line. That's the only reason why you do not have an error.

2. If you need to sort based on a calculated value from values from the aggregate, you can create a calculated column in the aggregate and use it in the Sort tab of the aggregate. Even if you need to Group By it probably will work. 

3. If you depend on things you are not able to join correctly using an aggregate but can use other techniques using SQL, you probably are better using SQL.

4. The alternative is to fetch data and sort the result list in logic, using one of the List Sort functions available (from system or extensions in Forge, or even to create one if no one satisfies your needs.

Cheers.

Thank you all for your colaboration.

I'm just a internal trainee and i stay blocked in that functionality for a long time. 


Good afternoon all