Syntax

Platform.Function.LookupOrderedRows(deName, sortCount, sortField, sortOrder, filterField, filterValue [, filterField2, filterValue2, ...])
6+ arguments

Parameters

Name Type Required Description
deName string Yes Data Extension name or external key
sortCount number Yes Maximum number of rows to return
sortField string Yes Column name to sort by
sortOrder string Yes "ASC" for ascending, "DESC" for descending
filterField string Yes Column name to filter on
filterValue string Yes Value to match in the filter column
filterField2 string No Additional filter column
filterValue2 string No Additional filter value

Description

LookupOrderedRows is the sorted, count-limited version of LookupRows. Use it when you need:

  • Results in a specific order
  • Only the top N rows (e.g., most recent 10 orders)
  • Pagination patterns

Examples

Get most recent 10 orders

var recentOrders = Platform.Function.LookupOrderedRows(
    "Orders",
    10,             // max rows
    "OrderDate",    // sort by
    "DESC",         // newest first
    "Status",       // filter field
    "complete"      // filter value
);

for (var i = 0, len = recentOrders.length; i < len; i++) {
    Write(recentOrders[i]["OrderID"] + "" + recentOrders[i]["Total"] + "<br>");
}

Top 5 products by price

var topProducts = Platform.Function.LookupOrderedRows(
    "Products",
    5,
    "Price",
    "DESC",
    "Active", "1"
);

All rows sorted (no effective limit)

Use a large sortCount to retrieve all matching rows in order:

var allRows = Platform.Function.LookupOrderedRows(
    "Customers",
    2000,         // effectively all
    "LastName",
    "ASC",
    "Active", "1"
);

See Also

See Also