29

Since quite a while we are able to sort on any fields with Record.SetCurrentKey(), even if the fields is not part of a defined key (even though not documented, but reported as document bug).


The corresponding functionality is missing on RecordRef.


On RecordRef we can only set sorting with the RecordRef.CurrentKeyIndex() function, which is bound to the defined Keys on the table.


I have a scenario where I need to find the maximum or minimum value of a given field, but without being able to sort on the specific field I have to loop all records to find out the largest/smallest value and this can of course have a huge negative impact on performance.


I suggest to add a new function on RecordRef with the following signature

RecordRef.SetAscending([FieldNo: Integer [, Ascending: Boolean]])

Parameters:

FieldNo: The number of the field that should be sorted on. If omitted, the sorting for RecordRef would be reset to the primary key in ascending order (similar as RecordRef.Reset(), but it doesn't reset filters)

Ascending: Specifies true if the field should be sorted in ascending order; otherwise false. Default is true.


To sort on more than one field, RecordRef.SetAscending should be called once for each field.


To first sort the RecordRef by field number 1 and then on field number 2:

RecordRef.SetAscending(1);
RecordRef.SetAscending(2);


To first sort the RecordRef by field number 1 descending and then on field number 2 ascending:

RecordRef.SetAscending(1, false);
RecordRef.SetAscending(2);



Category: Development
STATUS DETAILS
Needs Votes
Ideas Administrator

Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team

Comments

J

The reason I suggested the signature as I did, in contrast to the suggestion by Kishor Mistry, is that the number of fields that should be sorted on is probably dynamic and set by some kind of data in the database and thus cannot be added as parameters to the same function call.Looping the fields and calling RecRef.SetAscending() for each field would be more useful, IMO.

Category: Development

J

I agree with the need to be able to sort on any set of fields on a RecordRef, but I would suggest that this is implemented using SetCurrentKey(Field1, Field2, ... FieldN) and SetAcscending(Field, Ascending) the same as it is on a Record variable

Category: Development