Loop optimization and found-set traversal
ExpertCache counts, exit early, and avoid Go to Record [Next] to write loops that stay fast as record counts grow.
What you'll learn
- Why caching Get(FoundCount) matters
- How to use Exit Loop If correctly for early termination
- How Set Field by Name and variable batching reduce commit overhead
Naive loops in FileMaker scripts become slow because each "Go to Record [Next]" step commits any pending changes and re-evaluates relationships. Understanding how to structure loops — caching counts, exiting early, and batching field writes — can reduce run time by an order of magnitude on large found sets.
1/3
1
Cache the found count before the loop
Get(FoundCount) and Get(RecordCount) are recalculated on each call. Storing them in a variable once prevents redundant evaluations.
FileMaker Script
Set Variable [ $total ; Value: Get ( FoundCount ) ] Set Variable [ $i ; Value: 1 ] Go to Record/Request/Page [ First ] Loop Exit Loop If [ $i > $total ] # process current record Set Variable [ $i ; Value: $i + 1 ] Go to Record/Request/Page [ Next ; Exit after last ] End Loop
Sign in to track your progress and pick up where you left off.
Sign in to FM Dojo