B is for Boolean
A Boolean value is either true or false.
A Boolean expression is one that produces a Boolean value when evaluated.
FileMaker Pro uses Boolean expressions in a number of areas – calculations, scripts and object formatting to name a few. When creating an expression to be evaluated by the FileMaker calculation engine, you may use functions that either use or return a Boolean result.
The If function has the format:
If ( test ; result1 ; result2 )
The test is a Boolean expression. If it evaluates to true then result1 is returned, otherwise result2 is returned.
If ( Year (dateBirth) >= 1995; "Gen Z"; "Other")
The above example of an If expression will return the string “Gen Z” if the year of the date of birth for the record is greater than or equal to 1995; in all other cases, it will return the string “Other”.
Note that the FileMaker calculation engine also allows numeric results for the test where 0 (zero) is false and any non-zero numeric result is true.
DID YOU KNOW?
FileMaker provides the Case function for evaluating a series of tests.
If script step
The If script step has the structure:
If [ test ] # do script steps here if the test is true Else # do script steps here if the test is false End If
As for the If function, the test in the If script step should return a Boolean or a numeric result. If the test returns no data (null) or does not resolve into a number, then it evaluates to false.
The IsEmpty function has the format:
IsEmpty ( field )
It is a Boolean function returning 1 (true) if the specified field is empty; otherwise it returns 0 (false).
In addition to specifying a field name, you could also provide a text or numeric expression for evaluation.
The FileMaker calculation engine provides Boolean operators (and, or, xor, not) to construct more complex logic in expressions.
For example, the test in a If function:
If ( isEmpty ( discount ) and salescount > 10; 0.1 ; 0 )
For the test to return a true result (and therefore the function to return 0.1), both the expressions (separated by the and operator) must be true.
Other areas of use
You can also find Boolean expressions in:
- other functions – e.g. Case, Choose
- other script steps – e.g. Exit Loop If
- conditional formatting and visibility of layout objects
- security – record level access controlling view, edit and delete
- custom menus – conditional installation
Did you know?
FileMaker reserves the words true and false. Each of these returns what it says. So what would the following inane expression return? This or That?
If ( true and not false ; "This" ; "That" )