Over 46,000+ Business Solution Developers Find answers, ask questions, and connect with our community of business solutions developers, business owners and partners.
The IF script step ( in concert with the Else, Else If and End If steps ) allows you to branch a script into multiple directions. When a script runs and sees the IF step, it checks to see if the IF condition is TRUE or FALSE. If TRUE, then it will run the steps between the IF and the ELSE (or ELSE IF) step from top to bottom. If FALSE, ScriptMaker passes over all the steps until it reaches the ELSE (or ELSE IF) step. Then begins to run the script steps after the ELSE statement. The If script step must also include and Else and End If step to branch.
Here are a few example that the IF branch can be based upon…
a user choice ( like with the show message dialog box )
a value in a field ( like what the user entered on a particular record) an environmental condition ( when used in concert with Status or Design functions ) or just about anything that you can use a FileMaker calculation field to evaluate.
You can place an IF script step within another IF script step ( called nesting ) and this allows you to branch a script in more than two directions.
HOW IT IS USED
The IF Statement is one of the main areas that can separate the beginner
FileMaker script designers from the intermediate or advanced ones. You can build an almost unlimited level of functionality by using this step. Branching can be done based upon a users choices, users data entry, the environment of the computer / database / network and even password access level.
The Else script step is the fork in the road when you want to branch from an IF STATEMENT into two or more possible directions. When a script runs and sees the IF step, it checks to see if the IF condition is TRUE or FALSE. If TRUE, then it will run the steps between the IF and the ELSE from top to bottom. If FALSE, ScriptMaker passes over all the steps until the ELSE step. Then begins to run the script steps after the ELSE statement to it’s associated End If step.
There is an order that has to be adhered to in regards to the Else script step. It must appear between an If and End If script step. If it does not, FileMaker will bark at you when you try to close that script.
COOL IMPLEMENTATIONS OF IT
One of my favorites is when someone uses a Get function to see how big your computer screen is and then navigates to custom layouts for that size.
You can also use the IF statement to pass over a set of script steps by always having a False result. Below you can see that my blah, blah, blah action is passed over because 1 will never equal two.
IF ( 1 = 2)
blah, blah, blah,
IF statements are advanced levels for FileMaker. It’s almost always best to do them as separate subscripts unless you are an experienced IF STATEMENT commando.
At the time I’m writing this, I’m not sure when this script step appeared. I believe it was FileMaker 8 but it could have been as early as FileMaker 7. Basically it is a combination of the If and Else script steps. I wrote the following on purpose because it the actions are actually flipped (as the name implies).
The ElseIf needs to follow an IF script step (or another Else If) and it allows you to embed a calculation. If that calculation is a TRUE result (1=1 for example), then the script will perform all the script steps between that ELSE IF to a branch ending script step (such as another ELSE IF, END IF, Exit or Halt).
As I alluded to earlier, you can have many ELSE IF script steps in a scripts. This allows you to write a script that has an almost endless number of different branching actions.