Database Reference
In-Depth Information
Take the script you've created in this chapter, for example. Before it does anything else, your
Find Unpaid Invoices script goes to the “Invoices with Balance Due” layout—but what
would happen if you left that step out? Figure 11-8 shows the options for the Perform Find
script step. See if you can spot what's missing .
You can see that Perform Find —like most other script steps—makes no mention of which
table it should act upon. Just because you're asking it to “Find records when In-
voices::Balance Due > 0” doesn't mean you're looking for invoice records. You could be
looking for customers whose attached invoices have a balance due. Or you could be looking
for any line items on an unpaid invoice. FileMaker can tell what you're looking for only by
the context of the layout you're on. That's why the first step in the script goes to the “In-
voices with Balance Due” layout. That layout is attached to the Invoices table occurrence.
This tells FileMaker which records to look through (those in the Invoices table) and from
what perspective to resolve relationships (the Invoices table occurrence on the Relationships
graph).
When to Switch
Now that you've dutifully absorbed the lesson in the previous paragraphs, don't get lured in-
to the idea that you always have to switch to a layout for your script to work. The fact that a
script can do something useful from more than one context can be a good thing. In general,
you have three choices when you write a script, and here are some guidelines on when to use
each:
Switch to a layout associated with the table you want to work with . The Go to Lay-
out script step makes sense when you're showing certain results from a specific context,
as in the Find Unpaid Invoices script. If necessary, you can then switch back to the ori-
ginal layout at the end of the script ( Go to Layout has an Original Layout option).
Don't include a Go to Layout script step at all . Just let the script go about its busi-
ness, whatever the context. If you use this approach, then you have to make sure the
script works and makes sense from any perspective. For instance, a script could switch to
Preview mode, resize the window to show the whole page and then ask someone if he'd
like to print. This script can run on nearly any layout and still do something useful: print.
See the box on Context Independence for one example of context-independent scripting.
Prevent the script from running on the wrong layout . Using an If test in a script (see
the box on Conditional Breakpoints ) , you can make it so a script stops running if it's not
working properly on the current layout. This alternative is your best bet when switching
layouts within the script isn't feasible. For example, suppose you have a Refund Invoice
script that carries out the steps necessary to pay someone back. Using Go to Layout to
Search WWH ::




Custom Search