In Chapter 5, we showed you how to export data for a spreadsheet or accounting program. You can use a script to organize your data for export by different criteria, as well as to export only selected records.
1 .Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S).
2 .When the Define Scripts dialog box appears, click New.
3 .When the Edit Script dialog box appears, type a name in the Script Name box. We use Export by Payment.
4 .
In the step list on the left, scroll down to the Records category and double-click Export Records (Figure 7.40).
5 .In the Script Step Options section, check the "Specify output file" check box to choose a file name that will be used for the export file (Figure 7.41).
6 .When the Specify Output File dialog box appears, click Add File (Figure 7.42). When the Export Records to File dialog box appears, give the file a name, and specify where the file should be stored. If you don't specify a file name, you'll be prompted for one when the script runs.
7 .
From the Type drop-down list, select the type of text export for the file. In our example, we've selected Tab-Separated Text. Click Save (Figure 7.43).
8 .Click OK to return to the Edit Script dialog box.
9 .In the Script Step Options section, check the "Specify export order" check box.
10 .When the Specify Field Order for Export dialog box appears, select a field from the field list on the left. Then click Group By to use this file to organize your exported records (Figure 7.44).
In our example, we select Payment to organize our fields by the type of payment method (checks, credit card, purchase order or cash) customers used to pay invoices.
11 .From the field list on the left, double-click the fields that you want to export to the new file (Figure 7.45).
12 .If you are exporting a file that will be read on a different platform than the one you are working on, select the destination platform from the "Output file character set" drop-down list in the Options section (Figure 7.46).
13 .
Click OK to return to the Edit Script dialog box. The script step will display the name and file type of the export file. Click OK twice to finish.
You can repeat these steps to create new exports and their associated scripts.
Because FileMaker can build sophisticated relationships between different tables, it can also use data from these related tables in an export.
You can change the file name you specify for your export script at any time by returning to ScriptMaker and editing the script. First, highlight Export Records in the Edit Script script-assembly list. In Script Step Options, click the Specify button to the right of the "Specify output file" check box (Figure 7.47). This brings up the Specify Output File dialog box again, allowing you to select a new file name.
Once you've created several export sub-scripts, you can combine them into a master script to create and export different sets of data. For example, at the end of a quarter you might need to export your account sales data both to an accounting program and an Excel spreadsheet. A master script allows you to export the same data in both formats at the same time. To do this, follow the steps in "To create a master script" on page 153 to create a script that uses a series of Perform Script steps (Figure 7.48).