Using If with Else
Sometimes you'll want the script to do something when the answer to the If condition isn't yes. You use an Else step within an If so the script will choose a different action when the If statement isn't true. Else steps are only executed if the condition is not true. Otherwise, they're ignored.This script uses If and Else to change data in the Paid field for each record.
To use If and Else to modify data
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 Set Paid).3 .Under the Control category in the script step list on the left, double- click If.4 .In the Script Step Options section, click Specify to bring up the Specify Calculation dialog box.5 .In the field list on the left, scroll to find your field (we're using Balance Due). Double-click to add it to the formula box.6 .Choose the greater than (>) symbol from the Operators scrolling list by double- clicking it.7 .Type 0 (zero), then click OK. The formula box now displays the highlighted If statement with its condition (Figure 8.8). Click OK.
Figure 8.8. The If step checks to see if the amount in Balance Due is greater than 0.

Figure 8.9. Choose Set Field to insert new information into an existing field.

Figure 8.10. The Specify target field check box allows you to specify the field you want to change.

Figure 8.11. Choose or create the field you want in the Specify Field dialog box.

Figure 8.12. If there's a balance, Set Field marks the Paid field with an N for not paid.
[View full size image]

Figure 8.13. Else follows If in a script.
[View full size image]

Figure 8.14. The Y marks the field as Paid.

Commonly Used Get Functions
Although there are dozens of Get functions in the function list, some are much more useful than others. These are some of our favorites, which we use frequently in scripts we create.Date and TimeGet(CurrentDate)The current date according to your computer.Get(CurrentTime)The current time according to your computer.ScriptGet(LastError)The error code for the most recent error. See Chapter 10, "Script Troubleshooting" for more details about using this function.Get(LastMessageChoice)A number that stands for one of three possible buttons a user can choose from an alert message. All three can be changed using a Show Custom Dialog step in a script.1 = first button (by default, OK)2 = second button3 = third buttonGet(ScriptName)The name of the script that's currently active.Field and LayoutGet(ActiveFieldName)The name of the field where the cursor is active.Get(LayoutName)The name of the current layout.Get(LayoutTableName)The name of the table being used in the current layout.Get(PortalRowNumber)The number of the current portal row. If no portal is selected, this number will be 0.Get(ActiveRepetitionNumber)The number of the current repetition in a repeating field.DatabaseGet(FileName)The name of the current file.Get(FoundCount)The number of records in the current found set.Get(TotalRecordCount)The number of records in the table.Get(WindowMode)0 = Browse mode 1 = Find mode2 = Preview mode3 = Printing in progressGet(SortState)0 = unsorted 1 = sorted2 = partially (semi) sortedMulti-UserGet(MultiUserState)0 = sharing off1 = database accessed from a host2 = database accessed from local computerGet(UserName)The name of the user currently logging in to the local computer.Get(AccountName)The name of the current account (from Accounts & Privileges) logged in to FileMaker.System SettingsGet(SystemVersion)The version of the current operating system.Get(SystemPlatform)-1 = Macintosh-2 = Windows XP or Windows 2000Get(PrinterName)The printer name, driver name, and port name (Windows) or the Queue name and IP address of the current printer (Mac).
Using Get Functions
If you're having problems visualizing how you might use a Get function, here are some practical suggestions to jump-start your imagination:Date and TimeUse date and time functions in scripts to track changes and additions.LastMessageChoiceMake a user's choice in a custom dialog box the condition for an If/Else statement.LayoutNameWindowModeAccountNameEach of these functions is handy for scripting custom navigation within a database. You can fine-tune what each user sees and where they go in the database with these tools.FoundCountUse this function to determine whether or not a scripted Find had the desired results (for example, if no records were found). If you use it in combination with the Set Error Capture script step, it will enable a script to return a custom result for a scripted Find.SystemVersionSystemPlatformThese two functions can be invaluable if you have to adjust your scripts for older operating systems, fine-tune printing issues between Macs and Windows, or keep specialized FileMaker plug-ins straight on the different platforms.