If the whole purpose of scripting is to automate repetitious actions, the Loop step is probably the ultimate scripting command. Any steps you nest (create inside) in a Loop will continue until you tell it to stop.
The script in "To date and print an invoice using Get functions" prints invoices one record at a time. That's nice, but you still have to sit at your computer and run each record individually. Place the Print Invoices script inside a loop that prints automatically whenever it finds a balance in an account, and you can completely automate your invoicing process.
1 .
Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S). When the Define Scripts dialog box appears, click New.
2 .
When the Edit Script dialog box appears, type a descriptive name for the script in the Script Name text box (in this case Print All Invoices).
3 .In the step window on the left, in the Navigation section double-click Go to Record/Request/Page. Leave the Specify set to First.
4 .In the Control section, double-click Loop (Figure 8.31).
As with If and End If, FileMaker automatically inserts both Loop and End Loop in the script-assembly list.
5 .In the script step list on the left, double-click If (Figure 8.32).
Notice that If and End If are indented under the Loop step to indicate that they're running inside the Loop step.
6 .In the Script Step Options section, click Specify. When the Specify Calculation window appears, choose Balance Due from the field list on the left.
7 .Click the greater than (>) operator button and type 0 (Figure 8.33). Click OK. So far, this script looks to see if the Balance Due field is greater than 0.
8 .In the script step list on the left, double-click Perform Script.
Perform Script is indented one more level than the If statement, and two indents more than Loop (Figure 8.34). This structure is a visual clue to help you keep track of complicated nested scripts.
9 .In the Script Step Options section, click the Specify button and choose Print Invoices in the "Specify Script" Options dialog box (Figure 8.35). Click OK. If there's a balance in the first record, FileMaker will follow the steps in the Print Invoices script.
10 .To make sure that the next script steps are inserted after the If statement, click to select End If in the script-assembly list.
11 .Scroll down to the Navigation category in the script step list on the left and double-click Go to Record/Request/Page.
12 .In the Specify drop-down menu in the Script Step Options section, choose Next. Click the "Exit after last" check box (Figure 8.36).
These options tell the script to go to the next record in the table and exits after it processes the last one.
13 .Click OK twice to finish.