Running Scripts

At this point you're probably starting to see how scripts could be really useful in your database. The fact is, most large database systems are loaded with scripts that do all kinds of things. But the only way you've seen to run a script is pretty tedious: Chose Scripts ScriptMaker, select the script, and then click Perform. Thats lots of clicks to run a script that's supposed to save you time! Thankfully, there are a few other ways to run scripts that are more convenient, and you can set them up when you first create a script. Here are the possibilities:

13.3.1. The Scripts Menu

You can choose to show some or all of your scripts right in the Scripts menu. If you have a script or two that you want quick access to from anywhere, then it makes sense to put it in the Scripts menu. That way, anyone can run it by simply choosing it from the menu. There are even keyboard shortcuts for the first 10 scripts in the Scripts menu: Ctrl+1 (-1) through Ctrl+9 (-9) for the first nine, and Ctrl+0 (-0) for number 10. Figure 13-8 shows how to assign a script to this menu in the Define Scripts dialog box (Section 13.1.3).

Figure 13-8. Each script in the Define Scripts window has a checkbox by its name. When you turn this box on, the script shows in the Scripts menu all the time. If you're about to create a new script, you can turn the "Include in menu" checkbox at the bottom of the window on or off to tell FileMaker how you want your new script set. The inset picture shows the Scripts menu with some scripts listed at the bottom. Just choose one of these scripts to run it with no intervening dialog box.

 

13.3.2. Buttons

Throwing lots of scripts into the Scripts menu is a good way to give your users access to them no matter what context they're in. But what if you want to make a script available only on certain layouts? For scripts that apply only to the Invoices layout (like…oh…the Find Unpaid Invoices script), consider using buttons instead. When you add a button to the layout, FileMaker shows you the same Specify Button window you saw back on Section 6.6.5.3. Perform Script is the very first command available in the list (aside from Do Nothing). You can see the options associated with this button in Figure 13-9.

Figure 13-9. When you tell a button to execute the Perform Script command, you see the options shown in the background window. The Current Script pop-up menu lets you determine what FileMaker does when a script is already running. (You'll learn more about this option in Chapter 15.) When you click Specify, the foreground window appears. Here, you can choose a file from the pop-up menu (it shows all the files you have a file reference for, and lets you add a new file reference). The available scripts list then shows all the scripts in the selected file. You just select the script you want and click OK.

Using buttons, you can add one-click access to as many scripts as you want and you can place them where you want them. For example, you can put Invoice-related scripts on the Invoices layout and Payment-related scripts on the Payment layout. If you make sure your context-dependent scripts don't show up in the Scripts menu, you're adding another layer of assurance that FileMaker runs your scripts only from the right context.


Tip: If you want the ultimate in control over which of people get to see which scripts, and even which layout they can see them in, take a look at the Custom Menus section in Chapter 19. You need FileMaker Pro Advanced to create Custom Menus, but for many situations, this powerful feature alone is worth the price of admission.


13.3.3. Opening and Closing Scripts

Finally, you can tell FileMaker to automatically run a script when someone opens or closes the file. The opening script runs when you first open the file. You might use this script if you want to be greeted with the list of unpaid invoices first thing every morning. The closing script runs when you close the last window for an open file. This option is a little less common, but it has its uses: If you want to make sure other related files close whenever the main file closes (even if they have open windows), then you could write a script to close them all whenever you close the main file.

To make the selection, you need to visit the File Options dialog box (File File Options). In the File Options window, make sure the Open/Close tab is selected. In this window, you first turn on one of the "Perform script checkboxes (there's one under "When opening this file" and another under "When closing this file"). Then you can select one of your scripts from the associated pop-up menu. Figure 13-10 shows the result.

Figure 13-10. The Open/Close tab of the File Options window (File File Options) lets you tell FileMaker what to do when a user opens or closes a file. Most of this window is devoted to the things that are done when a file opens. Only the last checkbox (under "When closing this file) has to do with which script should run when the file closes.


Part I: Introduction to FileMaker Pro

Your First Database

Organizing and Editing Records

Building a New Database

Part II: Layout Basics

Layout Basics

Creating Layouts

Advanced Layouts and Reports

Part III: Multiple Tables and Relationships

Multiple Tables and Relationships

Advanced Relationship Techniques

Part IV: Calculations

Introduction to Calculations

Calculations and Data Types

Advanced Calculations

Extending Calculations

Part V: Scripting

Scripting Basics

Script Steps

Advanced Scripting

Part VI: Security and Integration

Security

Exporting and Importing

Sharing Your Database

Developer Utilities

Part VII: Appendixes

Appendix A. Getting Help

show all menu





FileMaker Pro 8. The Missing Manual
FileMaker Pro 8: The Missing Manual
ISBN: 0596005792
EAN: 2147483647
Year: 2004
Pages: 176
Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net