Reliable record references when AppleScripting FileMaker

Using current record when AppleScripting FileMaker has a couple of problems. The current record can change out from under you, so by the next step in your script, you may be dealing with the wrong record. Simply storing the record result in a variable doesn’t work either because getting the result converts it to a native AppleScript list of the data from the record. Using a reference to current record suffers the same problem.

One solution is to use record IDs. I believe that record IDs are guaranteed to be static/unchanging, at least while the app is running.

To get the record ID for the current record:
set recID to ID of current record

To use the record ID later in your script:
get cell "my_field" of record ID recID

To get all record IDs for a given query:
set recordIDs to ID of every record whose cell "my_field" is "my_value"

Then access each found record by ID:
repeat with recID in recordIDs
   get cell "my_other_field" of record ID recID
end repeat

Note: The following method will also work for certain use cases since it appears to use the record ID internally as well:
set x to current record as reference

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s