Sort Records patterns in scripts

Beginner

Script dynamic and multi-level sorts, detect the current sort state, and manage sort performance on large found sets.

What you'll learn

  • How to script a hard-coded multi-level sort
  • How to detect and skip redundant sorts
  • How to sort by a calculation or related field
  • How to toggle sort direction with a button script
  • How sort interacts with a found set on FileMaker Server

Sort Records is a frequent script step, but its interaction with portal sorts, found-set size, and sort state detection has several nuances that trip up developers. Scripting a sort correctly means choosing between a hard-coded sort order and a dynamic one, understanding when to re-sort vs keep the current sort, and knowing how to detect whether records are already sorted.

1/3
1

Script a multi-level sort

Sort Records has a built-in order editor in the script step. Add multiple sort fields with ascending or descending order. The sort is re-applied every time the script runs.

FileMaker Script
# Sort invoices: by Client ascending, then by Date descending
Sort Records [
  By: Invoices::ClientName (Ascending) ;
  Then by: Invoices::InvoiceDate (Descending) ;
  No dialog
]

# Check for sort error
If [ Get ( LastError ) != 0 ]
  Show Custom Dialog [ "Sort failed. Please try again." ]
End If

Sign in to track your progress and pick up where you left off.

Sign in to FM Dojo