User manual

Table Of Contents
Creating scripts to automate tasks
10-3
Creating scripts: an overview
Whether your FileMaker Pro scripts are simple or complex, you will
find that it is easier to create them if you:
1 plan the script before you define it.
1 perform certain operations, like Find requests and Sort order,
before you open ScriptMaker, thus making it easier to store the
parameters for these requests. See “Storing settings before creating a
script” on page 10-4 for more information.
Once you have a clear idea of how your script will be constructed and
have stored any necessary settings, you are ready to define the script.
Planning scripts
Just as you wouldn’t attempt to write a report without an outline, you
shouldn’t attempt to write a script without some forethought and
planning. Consider these points before defining a script:
1 What do you want to accomplish? Can you separate the job into
smaller tasks? If so, define a subscript for each small task, and then
define a script that performs the subscripts. It’s usually easier to
design and test several small subscripts than one complex script. This
modular approach also lets you reuse your subscripts in other scripts.
1 Is all the data you need in one file, or will the script operate on
more than one file? If you’re using multiple files, which ones should
the script open? Where should you define the script?
1 How will users perform the script? (See “Using buttons with
scripts,” on page 10-12.)
1 Will the script contain steps for print setup (Windows), page setup
(Mac OS), printing, importing, finding, sorting, or exporting? If so,
what settings should you store before defining the script? (See
“Storing settings before creating a script,” on page 10-4.)
1 Which fields and layouts will the script need? Some steps require
a field to be on the current layout (like Go to Field, Insert Text, Insert
Calculated Result, and Replace), while others, such as Set Field,
don’t. Use Go to Layout to switch to a layout that has the fields your
script requires.
1 Should the script switch among modes? For example, use Enter
Browse Mode before modifying data in fields and records, and use
Enter Find Mode before setting up a find request or finding data.
1 Should the script work on all records in the database, the current
found set, or a specific set of records? What if no records are found?
Use one of the find or omit steps to set up the correct records.
1 Which record should the script start with? For example, when
using the Loop step, decide whether the loop starts at the first or last
record, a specific record, or the current record in a found set. Use
Go to Record/Request/Page to select a starting record.
1 How should the script advance through multiple fields and
records? Use navigation steps to move through a found set.
1 Should the records be sorted before the script processes them? If
you use the Loop step, use Sort or Unsort before the loop to order
your records properly.
1 When should the script finish? After all records have been
processed? After a specified condition has been met? Use the If step
to perform a task when the script reaches a specified condition.
1 How will you document your script design? Use the Comment step
to make your scripts readable and understandable. This is especially
important if others will be maintaining a database that you create.
1 How will you test your script? Use the Pause/Resume Script step
to pause at specific points in your script. For example, if you are
testing a script with a Loop step, placing a Pause/Resume Script step
in the middle of the loop may allow you to see if your loop is working
as intended. You can remove the Pause/Resume script step when
your script is working properly.