It took quite a while to figure this out. Johan provided the essential clues on how to make lengthy loops much faster. The docs on this are definitely not clear (unless you already know what they’re trying to say).
getSelectedIndex(index) advances which record to display (even though it may not be actually show on screen, still takes processing time).
In contrast foundset.getRecord(index) simply identifies the target without actually navigating to it, thus saving time. However this function is non-functional unless you store its result in a variable. In fact so essential you can’t call up this function without also declaring a variable. The example in the docs is “var record = forms.companies.foundset.getRecord(10)”
Here’s what stumped me for quite a while because the docs are so damnably terse. The pointer to the target is now stored in the variable. The variable now has field (and other) properties. You can now do things like “record.companyName = ‘whatever’;”. You’re making a call to the target record without actually “getting” the record, despite the name of the function. You’re saying go to the record pointed to in the variable “record” and put “whatever” into its companyName field. You can also use the “record” prefix in front of relationship calls.```
if (databaseManager.hasRecords(record.comupdate$cat_to_catitem) == false)
var max = controller.getMaxRecordIndex();
for ( var i = 1 ; i < max ; i++ )
{
var record = foundset.getRecord(i);
// do something
}
Very important: initiate the variable i at 1, not zero otherwise you'll "go" to a non-existent index.
You're moving the pointer to subsequent records, taking action on those records without incurring the overhead of navigating there. Subtle, which took a while to catch on. We're definitely outside the world of FMP now. <img src="{SMILIES_PATH}/icon_wink.gif" alt=":wink:" title="Wink" /> Don't know how to boil this explanation down to fewer words without losing the communication.
My “inefficient method” hustles much faster. However with just 1100 records to process it still takes about three seconds from button click to screen refresh.
I’m now using the foundset.getRecord(index) technique throughout, I’m using relationships to load sets of records to process and using the database.hasRecords(relationship) to test whether a secondary operation needs to be taken.