Record.SetAscending(Any, Boolean) Method

Version: Available or changed with runtime version 1.0.

Sets the sort order for the records returned. Use this method after you have set the keys to sort after, using SETCURRENTKEY. The default sort order is ascending. You can use SETASCENDING to change the sort order to descending for a specific field, while the other fields in the specified key are sorted in ascending order.

Syntax

 Record.SetAscending(Field: Any, Ascending: Boolean)

Parameters

Record
 Type: Record
An instance of the Record data type.

Field
 Type: Any
The field that you want to set the sort order for.

Ascending
 Type: Boolean
The sort order. Specify false if data must be sorted in descending order; otherwise true.

Remarks

SetAscending is applicable to records that aren't displayed in a page in the client. For example, you can read data from an ODATA web service where data is sorted in ascending order on one field and descending on another. When the records are shown in a page, the method has no effect.

Example

The following code example shows how to use SetCurrentKey and SetAscending to sort data in two different directions based on two fields. It uses SetCurrentKey to specify the sort based on City and Name. Data will be sorted in ascending order based on those two fields, first by City, then by Name. Next, you use SetAscending to sort Name in descending order instead.

page 50100 MyCustomerList
{
    PageType = List;
    ApplicationArea = All;
    UsageCategory = Lists;
    SourceTable = Customer;

    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field("City"; City)
                {
                    ApplicationArea = All;
                }
                field(Name; Name)
                {
                    ApplicationArea = All;
                }
            }
        }

    }

    trigger OnOpenPage()
    begin
        SetCurrentKey(City, Name);
        SetAscending(Name, false);
    end;

}

If you publish the page as a web service, and read the OData feed, you'll see the records sorted in ascending alphabetical order by city and descending alphabetical order by name. However, if you open the page in the client the city and name are both sorted in ascending order.

SetCurrentKey Method Record Data Type
Get Started with AL
Developing Extensions