Database Reference
In-Depth Information
Sorting Records
After all that fuss about finding records, the sorting script steps are refreshingly simple.
There are only two and you already know how to use both. The
Sort Records
script step
behaves in a now-familiar way. By default, it brings up the Sort dialog box when the script
runs. If you turn on its “Specify sort order” option, then you can specify the sort order but al-
low users to change it. Finally, turn on the “Perform without dialog” option to sort the re-
cords without giving users a choice about the sort order.
If the records are already sorted, then you can
unsort
them from a script. For instance, you
might sort records for a report, but you want to return them to their unsorted order when the
report is finished so people don't get confused. Just use the
Unsort Records
script step. It
does its job with no options.
Sorting Records with an OnRecordLoad Trigger
When you first encountered a Sort script, you learned how to attach it to a layout with the
OnLayoutEnter
script trigger (
Creating a Simple Script Trigger
). That sorted your records
whenever you viewed the List layout. But if you switch that trigger to
OnRecordLoad
, you'll
get different behavior with that same script.
OnRecordLoad
fires whenever a new record is
loaded, but you can still sort the records a different way any time you need to.
If you do a find on a layout when the
OnLayoutEnter
trigger is set, the results come back
unsorted.
OnRecordLoad
changes the layout to automatically sort when you first view the
layout
and
when you find new records. The
OnRecordLoad
trigger fires whenever a new re-
cord is loaded, which always happens after a find. True, it happens when you switch records
too, but FileMaker is smart enough to know it doesn't need to sort an already-sorted list, so
this doesn't cause a slowdown. But whenever you visit the Customers layout, your records
are presorted. If you sort manually, then your new sort order sticks until you leave the layout
and come back (or sort manually again).
TIP
Use
OnRecordLoad
for list views, where you're not likely to do much data entry. But on a Form
view or a Detail layout, where you're creating lots of records, this script may trigger enough to af-
fect performance. In that case, use
OnLayoutEnter
instead.