Sets the sort order for the records returned. Use this function 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.

For example, you can read data from an ODATA web service where the data is sorted in ascending order on the Name field but in descending order on the City field.

[Ascending :=]Record.SETASCENDING(Field,[ SetAscending])

Parameters

Record

Type: Record

The record in the table that you want to set the sort order for.

Field

Type: Field

The field that you want to set the sort order for.

SetAscending

Type: Boolean

The sort order. Specify Descending if data must be sorted in descending order; otherwise Ascending.

Example

The following code example illustrates how you can use SETCURRENTKEY and SETASCENDING to sort data in two different directions based on two fields.

 Copy Code
Customer.SETCURRENTKEY(City,"Name");
Customer.SETASCENDING(City,Descending);

In this example, you use SETCURRENTKEY to specify that you want to sort based on City and Name. This means that data will be sorted in ascending order based on those two fields, first by City, then by Name. Next, you use SETASCENDING to sort City in descending order instead. As a result, your data will look like this:

 Copy Code
CTown
ACustomer
BCustomer
BTown
ACustomer
BCustomer
CCustomer
ATown
ACustomer
BCustomer

See Also