Ultimate Find
The title of this slide makes a big claim. Everyone's idea of the ultimate find script will vary. This script covers the core functionality a find script should incorporate. It covers four areas: no records found, no criteria entered, one record found and multiple records found. Something different happens depending on all of these find outcomes. Let's start by showing the entire script:

The Set Error Capture script step is used to prevent messages like the one that occurs when no records match your find request.

This message is quite confusing to a new user, especially if they choose to cancel the find. If you have taken them to a special find layout during the script, the user will be left on this layout. If they continue the script, the user will be left with a found set of no records found. This could cause them to worry since there will be no data showing. So, the Set Error Capture script step is used to capture these errors.
This leads us to the If statements that check to see if the error is equal to 400 or 401. Error 401 is FileMaker's internal code for no records found and 400 is the error for no criteria entered. When you turn on error capturing in a script, you take on the responsibility of all errors that could occur. That means you have to think like a user and figure out all the ways an error could be produced. In the find example, the only two errors that could be created are no records match and no criteria entered.
In the case of no records found, it is very likely that the user has mistyped the find criteria. That is why the choice of modifying their last find is given. If they choose to modify the last find, the Modify Last Find script command will be invoked and the find script will be run again. However, you need to skip some of the script commands at the beginning or the previous find criteria will not be shown. That is why the beginning of the script tests to see if the current layout is the Find layout. If it is, you know the user is modifying the last find and there is no need to enter find mode again.
If error 400 occurs, this script simply places them on the layout they started on with a found set of all the records. If you would prefer to restore the found set as it was before the user initiated the find, you can use the technique discussed in the previous slide that demonstrates how to isolate a record.
TIP: Errors are stored temporarily in memory for one script step after the error occurs. In the find example provided, two possible errors could occur. Therefore, the current error is set to the Error global field. If your script can only result in a single error, there is no need to set the error to a global field. Just test for it with the Status(CurrentError) function in an If script step.
Finally, if the find is successful, a choice is made whether to go to a list view or a form view. If a single record is found, form view is selected. If multiple records are found, a list view is selected.
Download an example FileMaker file
.
DONE
|