0 Replies Latest reply on Aug 2, 2013 1:58 PM by SkeletonKey

    Quickly Navigating to a Specific Record Within a Found Set by Greg Lane

    SkeletonKey

      Quickly Navigating to a Specific Record Within a Found Set

      Blog by Greg Lane

       

       

      Recently I needed to have a FileMaker Pro 12 script navigate to a particular record within the found set after performing some action. There are several situations where this could occur, such as a scripted Extend Found Set or Constrain Found Set or perhaps when looping through the found set and either omitting, deleting, or duplicating certain records.

       

      My first thought was to simply capture the ID of the current record at the beginning of the script and then loop through the found set at the end of the script and exit the loop on the correct record. What I discovered was that this was unacceptably slow with larger record sets. So here's a better method. (By the way, thanks to Jeremy Bante and Jesse Barnum who both reminded me that this technique is called a binary search.)

       

      The solution I came up with looks something like this:

      • If the records are sorted, unsort them
      • Navigate to the middle of the found set
      • If the target record is greater than the current record, navigate to the middle of the second half
      • If the target record is less than the current record, navigate to the middle of the first half
      • Continue this pattern, splitting the remaining records in half in each iteration until we arrive at the correct record
      • If the records were sorted, sort them

       

      The script works by relying on two facts:

      Read more...