Scripts are the lifeblood of an interactive FileMaker solution. In this section we try to distill FileMaker scripting down to its essentials.
All script editing is done within the FileMaker ScriptMaker, shown in Figures 9.1 and 9.2. ScriptMaker lives in the Scripts menu and is accessible from the keyboard via images/U2318.jpg border=0>-Shift-S or Ctrl-Shift-S.
The interface depicted is the one available in FileMaker Pro Advanced (FMPA). FMPA has some scripting features not available in the regular FileMaker Pro client, such as the capability to copy and paste scripts and script steps, and to disable script steps. These differences are called out in the diagrams.
There are a large number of time-saving shortcuts available in ScriptMaker. We list these in the section of this book devoted to shortcuts.
For more information on shortcuts available within ScriptMaker, please see "Scripting" in Chapter 12, "FileMaker Keyboard Shortcuts."
Scripts are attached to an individual file (no matter how many tables the file has). Though one script may call a script in another file, a given script may only act directly on data and records that are contained or referenced in the same file as the script.
Scripts may also be moved between files in several ways. From within ScriptMaker, its possible to import scripts from another file. Simply click the Import button in ScriptMaker, navigate to the file containing the scripts you want to import, and then click a checkbox for each script you want to bring over, and import. FileMaker will move the scripts and do its best to resolve any references they contain (references to files, scripts, or value lists, for example), though you should still check over the scripts and fix any references that might not have translated correctly.
Using FileMaker Advanced, its also possible to copy and paste scripts, either singly or in blocks, both between files and within the same file (where the effect is the same as duplicating the scripts). Copying scripts between files is identical to the older import mechanism, but might feel more natural or convenient to some.
Access to scripts is controlled via FileMakers Accounts and Privileges setting. A given privilege set may be allowed to edit and execute scripts, to execute only, or may not be permitted to use scripts at all. These settings can be customized on a per-privilege-set, per-script basis.
When a script is executed, it will run with the privileges of the current user. For example, if a script tries to delete a record, and the user running that script does not have sufficient privileges to delete that record, the script step will fail.
This hurdle can be overcome by checking the Run Script with Full Access Privileges checkbox within ScriptMaker, for a specific script. When this option is selected, the script will run as though the current user has the [Full Access] privilege set. Note that if you use a function such as Get(PrivilegeSetName) while such a script is running, the function will return [Full Access]. It will not return the name of the privilege set normally associated with the current users account.
Unlike other parts of the FileMaker development environment, ScriptMaker has relatively few tools for organizing scripts. In particular, its not possible to sort scripts in any way. Rather than relying on a built-in feature of ScriptMaker, youll need to devise a scheme for keeping your scripts organized manually. Here are a few common methods for organizing scripts:
FileMaker Pro Advanced contains some powerful script debugging tools: the Script Debugger and the Data Viewer. The Script Debugger enables you to step through running scripts line by line, with fine-grained control over execution, while the Data Viewer enables you to watch the values of selected fields and expressions, and will often be used along with the Script Debugger to watch the values of data and expressions as a given script executes. Figure 9.3 shows the Script Debugger interface.
A full explanation of these tools is beyond the scope of this reference, though we do list the essential Script Debugger shortcuts in the chapter of this book that pertains to shortcuts.
FileMaker Pro Advanced includes one other useful addition for script troubleshooting: the Disable Script Step feature. If you select one or more script steps and click the Disable button in ScriptMaker, those steps will be disabled and will not execute. This allows you to quickly "comment out" sections of a script as part of a troubleshooting effort.
Scripts can be invoked from a web-published FileMaker database, both via Instant Web Publishing (IWP) and via Custom Web Publishing (CWP). But not all script steps can be run from the Web. ScriptMakers "Show Web Compatibility" checkbox provides a visual indication of which steps will and will not work on the Web. (In general, any script step that requires user interaction, such as a confirmation dialog, or a script step that opens some element of the FileMaker interface such as the Define Database dialog, will not be web-compatible.)
If a script executed from the Web contains one or more non-web-compatible script steps, the non-compatible script steps will either be skipped, or else the script will stop in its entirety. Which of these occurs depends on whether Allow User Abort is set to On or Off in the script. If Allow User Abort is set to Off, unsupported script steps will be skipped. If Allow User Abort is set to On, an unsupported script step will cause the script to stop completely.
: FileMaker Specifications
FileMaker 8 Product Line
Specifications and Storage Limits
Field Types and Import/Export Formats
: Calculation Functions
Working with Calculations Primer
: Custom Functions
Custom Functions Primer
Useful Custom Functions
: Script Steps
Script Step Reference
: Quick Reference
FileMaker Error Codes
FileMaker Keyboard Shortcuts
FileMaker Network Ports
FileMaker Server Command Line Reference
FileMaker XML Reference
: Other Resources
Where to Go for More Information