If
Evaluates a Boolean calculation and performs a conditional action based on that evaluation.
See also
Options
Specify the Boolean calculation you want evaluated.
Compatibility
Product | Supported |
FileMaker Pro | Yes |
FileMaker Go | Yes |
FileMaker WebDirect | Yes |
FileMaker Server | Yes |
FileMaker Cloud | Yes |
FileMaker Data API | Yes |
Custom Web Publishing | Yes |
Originated in version
6.0 or earlier
Description
If the calculation result is any number except zero, the calculation evaluates to true and the subsequent script steps are executed. If the calculation result is zero, no data, or does not resolve into a number, then the calculation evaluates to false and the subsequent script steps are not executed.
Every If step must have a corresponding End If script step somewhere after the If step and at the same indentation. Whenever you use an If script step, the script editing pane automatically enters an End If step.
You can also add additional conditions by using the Else If script step and Else script step.
Notes
- If you do not specify a calculation or if the calculation is unsuccessful, it will evaluate as false. Use the Get(LastError) function to capture these errors.
Example 1
Performs a find. If no records are found, displays all records and sorts.
Perform Find [Restore]
If [Get (FoundCount) = 0]
Show All Records
Sort Records [Restore; With dialog: Off]
End If
Example 2
Performs a find. If no records are found, displays a custom dialog box. If records are found, sorts the found set.
Perform Find [Restore]
If [Get ( FoundCount ) = 0]
Show Custom Dialog ["Find Records"; "No records were found."]
Else
Sort Records [Restore; With dialog: Off]
End If
Example 3
Performs a find. If no records are found, displays a custom dialog box. If one record is found, goes to the Invoice Details layout. If more than one record is found, goes to the Invoices layout.
Perform Find [Restore]
If [Get (FoundCount) = 0]
Show Custom Dialog ["Find Records"; "No record was found."]
Else If [Get (FoundCount) = 1]
Go to Layout ["Invoice Details"]
Else
Go to Layout ["Invoices"]
End If
Example 4
Performs a find. If no records are found, displays a custom dialog box so the user can run the Find Invoices script to search again. If one record is found, goes to the Invoice Details layout. If more than one record is found, goes to the Invoices layout.
Script: Find Invoices
Perform Find [ ]
If [Get ( FoundCount ) = 0]
Show Custom Dialog ["No Record Found"; "No records were found. Do you want to search again?"]
If [Get ( LastMessageChoice ) = 1]
#Calls this script again as a sub-script
Perform Script [Specified: From list; "Find Invoices" ; Parameter: ]
Else
Show All Records
End If
Else If [Get ( FoundCount ) = 1]
Go to Layout ["Invoice Details"]
Else
Go to Layout ["Invoices"]
End If
Sort Records [Restore; With dialog: Off]