Canceling / Aborting A Scripted FileMaker Find Operation

From Dwayne Wright PMP, PMI-ACP, CSM
Certified FileMaker Developer

WEB: www.dwaynewright.com
EMAIL: info@dwaynewright.com
TWITTER: dwaynewright
YOUTUBE: FileMakerThoughts

If a user of a FileMaker database cancels a scripted find due to receiving the “no records are found” message, you may need to direct the script to show all the records and go to another layout.

You can prevent a users ability to cancel a script using the Allow User Abort [ OFF ] at the beginning of a script. Since ScriptMaker runs script steps from top to bottom, you will need to locate your Allow User Abort [ Off ] and Allow User Abort [ On ] in the correct places. If you have script steps above the Allow User Abort [ Off ] script step, the user can cancel the script up to the point Allow User Abort step appears.

If you allow a user to abort a scripted find and the “no records are found” message is encountered ... you have little control of the outcome. There are two ways to trap for the “no records are found” message. Both of these methods will require you to use a Get Function. Get Functions capture what is going on in FileMaker or in the computer system running FileMaker at a particular point in time.

FIRST OPTION, The Get(LastError) Function.
Using this method, we detect what error was returned by FileMaker. While a script is running, this get function will return a numerical result for any encountered error. For the function to work properly, the script step of Set Error Capture [ on ] needs to in use before you can trap the error. We all have had the experience of encountering a FileMaker error message. The most common occurrence is when FileMaker tells you that it didn't find any records that match your settings in a find command. Which isn't so much an error as a condition message from FileMaker.

Some of the messages you get from FileMaker after an error might be confusing, particularly to the users that are not familiar with FileMaker. The Set Error Capture step is the fundamental first step that allows ScriptMaker to detect errors in advance and instead of showing FileMakers error message ... allows the developer run a set of script steps. When Set Error Capture script step is included in a script and is set to the ON position, FileMaker's Error Messages to the user is off while the script is running. You then can use the IF, ELSE and END IF scripts steps are part of your error handling routine.

This is good if you want to trap for an error condition in a script and build a customized reaction ( such as a customized dialog box or performing a subscript ). A listing of all the error code numbers can be found in the online help of FileMaker. So our script would look something like this ...

If (Get(LastError) > 0)
Show Message ( No records found )
Show All Records
Go to layout ("whatever you specify")
Else
Go to layout ( to view the results)
End If

SECOND OPTION, The Get ( FoundCount )
This function will return a result that matches the number of records in the current found set. This can even go beyond the no records found option. You can branch is no records are found, just like above. However, you can also branch if your scripted search returned just one record, you would go to a form view. However, if the returned found set is more than one record, you might want to take the user to a list view layout.

If (Get ( FoundCount ) <1)
Show Message ( No records found )
Show All Records
Go to layout ("whatever you specify")
Else
Go to layout ( to view the results)
End If

 

=
More info about the author and FileMaker in general, contact me at info@dwaynewright.com.

© 2008 - Dwayne Wright - dwaynewright.com

The material on this document is offered AS IS. There is NO REPRESENTATION OR WARRANTY, expressed or implied, nor does any other contributor to this document. WARRANTIES OF MERCHANT ABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED. Consequential and incidental damages are expressly excluded. FileMaker Pro is the registered trademark of FileMaker Inc.