Home | About MACC | Clients | DADI | FMP Tutorial | MacFantastique

FMPRO Session 5 Scripting
Tips, Tricks & Shortcuts

The more time you spend planning your script, the more likely you are to accomplish what you want. Ask yourself these questions

  • Can you separate the task into smaller tasks? You can define sub-scripts for each small task, and then define a script that performs the sub-scripts. It's easier to design and test several small scripts than one complex one. Reuse sub-scripts in other areas. (Use Perform Script to perform a sub-script inside other scripts.)
  • Is all the data you need in one database file, or will the script operate on more than one file? If you're using multiple files, which ones should the script open? In which file should the script(s) be defined?
  • Which record should the script start with? For example, when using the Loop script step, decide whether the loop starts at the first or last record, a specific record, or the current record in the found set. (Use Go to Record/Request/Page, Go to Related Record, or Go to Portal/Row to set a starting record. If you don't include a navigation script step to determine the current record, the loop begins with the current record when the script is begun.)
  • Should the script switch among modes? A script can be run from Browse, Find, Layout, or Preview modes. Make sure your script is in the proper mode before it acts upon something. For example, use Enter Browse Mode to modify data in fields and records, and use Enter Find Mode to set up or perform a find request.
  • Which fields and layouts will the script need? Some steps require a field to be on the current layout (like Go to Field, Paste Literal, Paste Result, and Replace) while others don't (Set Field). Use Go to Layout to switch to a layout that has the fields your script requires.
  • Should the script work on all records in the database, the current found set, or a specific set of records? (Use Perform Find, Find All, Find Omitted, Omit, Omit Multiple, and Modify Last Find to include only the records that you want to work with in the found set.)
  • Should the records be processed in a certain order? Decide among the current sort order, a specified sort order, or unsorted (the order the records were created in). Use the Sort and Unsort script steps before entering a loop to order your records properly before processing them.
  • How should the script advance through multiple fields or records? (Use Go to Record/Request/Page, Loop, Exit Loop If and End Loop to control multiple field or record processing).
  • When should the script finish? After all records have been processed? After a specified condition has been met? (Use If and Exit Loop If to perform a task when the script reaches a specified condition.)
  • How will you test your script? Use Pause/Resume to pause at predefined points in your script. Save a clone of your database, and then define and test your script in it to preserve the original data. After testing the script, import data from the original file into the clone.
  • How will you handle error conditions (such as an empty found set)? You can turn on error capturing (using Set Error Capture), capture the error (using the Status (CurrentError) function), then specify what should happen when that situation happens (with If and Else).
  • How will users perform the script? You either need to create a button to perform the script or specify that the script be added to the Script menu. Scripts can also be run from the Define Scripts dialog box or when a database is opened or closed.
Once you've considered these questions, you're ready to set up the database for your script.
  • Trick Since FileMaker Pro lets you create scripts, you don’t have to remember how to sort, search, or print your report. But how do you remember what a particular script was for? In FileMaker Pro 3, there is a way to do this. You can use the new Comment script step to write a short description and document the script.
Using Buttons
  • A button consists of the object you click on the layout and a button definition that tells FileMaker Pro which step or script to perform. For example, you could define a button that performs a script that finds, sorts, and prints records, or one that transfers information from one FileMaker Pro file to another.
  • You can use any object or group of objects, including a field, as a button. Copy an existing button, or use text and graphics to design your own button. If you select multiple objects, FileMaker Pro groups them together when you convert them to a button.
Note To use a button to perform several steps, define a script that includes the steps. Then define a button to perform the script.Working with Pauses
  • When a pause is built into a script, FileMaker Pro performs the script up to the pause and then waits indefinitely or for the specified pause duration. While the script is paused, you can do unscripted tasks. If you have not specified a pause duration, click Continue in the status area or press Enter to continue the script.
  • If you change layouts while a script is paused and then continue the script, the remaining script steps occur in the new layout. You can not stop a paused script using Command-Period if the script writer has set Allow User Abort (off).
  • To stop a paused script, you can:
    • click Cancel in the status area
    • switch to another mode
    • close the active window
    • quit FileMaker Pro
  • You can also perform another script from a button or the Script menu when a script is paused. FileMaker Pro exits the paused script and returns to the script that called the paused script.

  next - Updated Tuesday, March 8, 2005


Jump Menu