The Importance of the Layout

In a script, the active layout is very important, since it’s what determines the script’s context. Context is critical when you do things like delete records. If you write a script that simply deletes a record, without checking for context, it deletes the current record from whatever layout the user happens to be on. That may not be the right record at all. You could end up deleting a record from the Customer table instead of the single invoice record you meant to delete!

Take the script you’ve created in this chapter, for example. Before it does anything else, your Find Unpaid Invoices script goes to the Invoice List layout—but what would happen if you left that step out? Figure 13-5 shows the options ScriptMaker gives you for the Perform Find script step. See if you can spot what’s missing.

You can see that Perform Find—like every other script step—makes absolutely no mention of which table it should act upon. Just because you’re asking it to “Find records when Invoices::Invoice ID > 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 that are on an unpaid invoice. The only way FileMaker can tell what you’re looking for is by the context of the layout you’re on. That’s why the first step in the script goes to the Invoice List layout. That layout is attached to the Invoices table occurrence. This tells FileMaker which records to look ...

Get FileMaker Pro 9: The Missing Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.