Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Understanding the If script step

From: FileMaker Pro 11 Essential Training

Video: Understanding the If script step

Creating Scripts in FileMaker is an essential part of developing a FileMaker database, and making Scripts as intelligent as possible will take much of the guesswork out of using your database. A great way to add intelligence to your Scripts is by adding conditions to the Scripts. That way they are given instructions on what to do in certain cases, and that way you can have a Script that actually have many different results, depending on these conditions that you set up. If you recall in the Calculations chapter, we discussed a group of functions that we're calling the Logical Functions, that allow you to perform a test or ask a question, let's say, and then you provide multiple different results depending on whether or not the question was true or false. Or if you have multiple questions, you provide different results depending on what part was true.

Understanding the If script step

Creating Scripts in FileMaker is an essential part of developing a FileMaker database, and making Scripts as intelligent as possible will take much of the guesswork out of using your database. A great way to add intelligence to your Scripts is by adding conditions to the Scripts. That way they are given instructions on what to do in certain cases, and that way you can have a Script that actually have many different results, depending on these conditions that you set up. If you recall in the Calculations chapter, we discussed a group of functions that we're calling the Logical Functions, that allow you to perform a test or ask a question, let's say, and then you provide multiple different results depending on whether or not the question was true or false. Or if you have multiple questions, you provide different results depending on what part was true.

You can do the same thing in a Script using a set of Script Steps based on the If Script Step. So the If Script allows you to ask a question during a Script and then perform different actions based on whether or not the conditions were met. Let's take a look at these set of Scripts by opening up our exercise file and then opening up Scripts > Manage Scripts, and we'll see our Print Welcome Letter Script that we had created previously, and now we're going to hit the Duplicate button, and we see a new Print Welcome Letter Copy has been created. Let's double-click on that to open it up, and we see all the steps that we had in here previously.

All we're going to do is we're going to modify this Script. We're going to modify this a little bit because here we were doing the Find on behalf of the user. Instead what we're going to do is we're going to take the user into Find mode and allow them to create the Find criteria. Then we're going to perform the rest of the steps against their remaining Found Set. But in our Script, when they actually hit the Print button, it's going to check to see what the status of the user is, and depending on what their status is, it's going to take them to one layout, which would be the Welcome Letter layout. And if the Status is Inactive, for example, it's going to take them to a new layout that we've got called the Welcome Letter Inactive version, which both say different things.

So this way they can go through one record at a time, and every time they hit the Print button, it's going to automatically take them to the correct letter, so that it can be printed. So first we're going to clean up a couple of things; we'll get rid of the Perform Find, and we will keep all the rest of them for right now. But what we're going to do is, instead of navigating them to the layout, we're going to say If. Double-clicking on If will actually add two Script Steps. You see we've got the first Script Step If and then the second Script Step End If. The If starts the test and the End If ends the test, because if you remember in our Calculations, we had an area that was inside parentheses that determined what our test was going to be.

So this way this Script knows when we're done testing, and then it can perform the condition based on the result. So If will always be at the beginning and just like bookends, the End If will be at the end of our test. So we'll want to place the If step where we want to add the condition, so in this case, it's going to start at the very beginning of our Script. And then End If will be after the Go To Layout. Now, this means that every step that falls in between If and End If will only perform based on a condition. Now in order to create that condition, we have to double-click on the If Script Step, or we can hit the Specify button; in either case it takes us to the Specify Calculation dialog.

Now this Specify Calculation dialog is a little bit different than the one that we've been using recently because you see there are no results on the bottom. In this case, you see the Calculation result must be Boolean, not a field type or a file type; it just has to either be true or false or yes or no. So we have to take that into account when we're writing our test, for example. So if you remember, our goal here is to find out what the Status of the Customer is, and then based on the Status we're going to send them to a certain Layout to print. So let's say, first if Status or Customers Status equals, then we'll put in Inactive, and then we'll hit OK.

So now we're saying the test is If the Customers Status equals Inactive, then we want to do something, and then of course we're done with the test. Well, right now we're telling it to do something, and that do something is Go to the Welcome Letter layout. But if you recall, we've got a new layout that's called Customer Inactive Letter. So now we know that if it's Inactive it has to go to the Inactive Letter, but what about if it's not Inactive? Well, that's where these other items come into play. If you remember in the If Step inside Calculations, you can say If, and then you have a test, and then you have result number one or result number two, so basically you're saying If this test is true then do this; otherwise, do something else, and Else acts as the otherwise.

So here, I can say If the Customers Status is Inactive, go to this layout, otherwise we're going to have it go to another layout, which you might not realize is you can select an existing Step and hit Duplicate, then use the handles to move it down to the appropriate location, and now we can have this print our regular Welcome Letter. So now our Script says, If the Customers Status equals Inactive, then go print the Inactive Letter; otherwise, print the regular Welcome Letter. And now you see also we can go down here to our Custom Dialog window, and we can make it a little bit more specific, for example. You see here how it says, "Your Letter Has Been Printed".

I want to introduce you to another concept that's called setting a Variable. If you double-click on this Set a Variable, this is something that's similar to when you're using a Calculator. You do 2+2=4, and then you save that 4 to memory. So this allows you to save something to, let's say, like a Clipboard. You're familiar with doing Copy and Paste. Well imagine if you had a Clipboard that when you save something to the Clipboard you could save it and name it, so that you could save multiple things to the Clipboard that don't overwrite each other, unless of course they had the same name.

In FileMaker that's the same concept that we use here for a variable. In this case, I'm going to double-click on the variable, and we need to name it something. And inside FileMaker, you have to precede the name of a variable with a dollar sign, and then I'm going to put the word Status, and now we have to save a value to this field. So when it's on a record, it's going to save the Status here to Customer and we hit OK. So now what this means is that after it determines that some thing is Inactive, it's going to go to a certain layout and set a variable, or save a little piece in the memory of FileMaker, and name that dollar sign Status and to that little piece of memory in FileMaker it's going to put the term Inactive, in this case.

Otherwise, and we'll hit Duplicate, if it's not Inactive, it'll go to a different layout and save a different value. Now the reason that we're doing that is because, in our Custom dialog, you see we can specify Your, and now I'm going to create some text, space, quote, ampersand, and now I'm going to reference that variable. Variables are a little bit of an intermediate or advanced concept, but I wanted to at least briefly introduce you to them here because they are a pretty important part of scripting, as you get more familiar with scripting.

Again, it's just a little way to set something to a memory then pull that back from memory later, and here you see we're referencing it later on in our Script. So let's take a look at how this Script is going to work. We'll hit Save, we hit OK and we go into Layout mode and we select the button, Format > Button Setup, and it already says Perform Script, but let's pick a new one, the Welcome Letter Copy, and let's hit OK. Now let's take a look at how this works in Browse mode.

First, let's do a Find, Find, and let's say Find everybody in the State of Texas. It gives us three records, first record, Status of Pending, so they're not Inactive. This one is Inactive, and the last one is Pending. So let's see what happens when we run our Script on this record. You see what it does is it creates the Welcome Letter, but in this case it's printing more than one record. To remember how we can affect that, we can go into our Script, Print Welcome Letter Copy, hit Edit - by the way we can name this Inactive - and down in the Print, we can say Current record. Remember that allowed us to toggle between those and the two different Scripts.

So now let's try. We go to the first record. Sure enough, we get one record, and you see it's the Welcome Letter, and you also see that our Status shows up in the pop-up window. Now let's try going to another record, same Script, but this one is Inactive. Now we hit OK, and we see it's printed in Inactive Letter, and it's called at the Inactive Letter. So it's the same Script, but in this case we've added a condition using the If Script Step or the family of Script Steps, and we've also passed through using something that's called a Variable inside of the Script, which allows the same Script to have two different results based on a condition that we've developed inside of the database.

Show transcript

This video is part of

Image for FileMaker Pro 11 Essential Training
FileMaker Pro 11 Essential Training

94 video lessons · 14895 viewers

Cris Ippolite
Author

 
Expand all | Collapse all
  1. 7m 22s
    1. Welcome
      1m 8s
    2. Understanding the FileMaker family
      2m 15s
    3. Using the FileMaker Quick Start screen
      2m 52s
    4. Using the exercise files
      1m 7s
  2. 21m 9s
    1. What is a database?
      2m 26s
    2. Flat vs. relational databases
      2m 29s
    3. How FileMaker works
      4m 48s
    4. Understanding the essential preferences
      3m 13s
    5. Touring the interface
      8m 13s
  3. 11m 44s
    1. Creating databases from templates
      2m 29s
    2. Creating new databases in the spreadsheet-like format
      5m 35s
    3. Importing tables
      3m 40s
  4. 9m 9s
    1. Determining which tables you will need
      5m 10s
    2. Creating tables in the Managing Tables window
      3m 59s
  5. 34m 47s
    1. Understanding relationship types
      6m 58s
    2. Diagramming relationships (with ER diagrams)
      8m 50s
    3. Determining which key fields you need
      5m 18s
    4. Defining primary and foreign keys
      7m 56s
    5. Creating relationships using the relationships graph and table occurrences
      5m 45s
  6. 50m 34s
    1. Deciding what fields you will need
      5m 34s
    2. Understanding field types
      7m 54s
    3. Defining fields
      9m 56s
    4. Using Auto Enter options in fields
      9m 33s
    5. Reviewing field validation options
      8m 16s
    6. Building with container fields
      9m 21s
  7. 14m 8s
    1. Creating and duplicating records
      5m 40s
    2. Editing and locking records
      4m 42s
    3. Deleting records and backing up files
      3m 46s
  8. 21m 6s
    1. Importing data
      9m 57s
    2. Importing records to refresh data
      7m 2s
    3. Exporting data
      4m 7s
  9. 18m 30s
    1. Understanding layouts
      4m 15s
    2. Using the Layout Assistant to create List views
      7m 59s
    3. Using the Layout Assistant to create labels and envelopes
      6m 16s
  10. 27m 11s
    1. Using the Layout Setup dialog box
      4m 54s
    2. Understanding layout parts
      4m 40s
    3. Understanding the new Inspector
      2m 26s
    4. Exploring the Status Area in Layout mode
      6m 46s
    5. Managing layouts and layout folders
      8m 25s
  11. 41m 9s
    1. Arranging, aligning, grouping, and locking layout objects
      11m 5s
    2. Placing and formatting objects, parts, and graphics
      4m 10s
    3. Formatting fields and applying field attributes
      8m 26s
    4. Setting field behaviors
      4m 4s
    5. Using the Tab Control feature
      9m 8s
    6. Setting tab order
      4m 16s
  12. 36m 48s
    1. Using the basic find functions
      7m 31s
    2. Reviewing new requests in the Find mode
      5m 54s
    3. Establishing search operators
      6m 43s
    4. Constraining or extending found sets
      3m 24s
    5. Finding records using date, time, or timestamp criteria
      5m 18s
    6. Using Fast Match and Quick Find
      4m 41s
    7. Working with saved finds
      3m 17s
  13. 17m 28s
    1. Sorting with one criterion
      6m 4s
    2. Sorting with related fields
      2m 18s
    3. Sorting with multiple criteria
      1m 36s
    4. Sorting using custom values
      3m 14s
    5. Sorting using buttons
      4m 16s
  14. 17m 14s
    1. Reviewing Field/Control styles
      5m 43s
    2. Creating and applying static value lists
      5m 20s
    3. Creating and applying dynamic value lists
      6m 11s
  15. 23m 52s
    1. Previewing pages and print options
      6m 20s
    2. Printing in different views
      2m 54s
    3. Sliding objects
      3m 26s
    4. Printing merge letters
      4m 53s
    5. Saving as a PDF or Excel file
      6m 19s
  16. 15m 1s
    1. Building simple reports with summary fields
      4m 36s
    2. Creating subsummary reports
      6m 51s
    3. Creating subsummary reports in Table view
      3m 34s
  17. 52m 19s
    1. Defining calculations
      2m 31s
    2. Exploring the Calculation dialog box
      5m 8s
    3. Using number functions
      12m 41s
    4. Using date and time functions
      4m 58s
    5. Using text functions
      11m 43s
    6. Using get functions
      4m 0s
    7. Using logic functions
      11m 18s
  18. 46m 56s
    1. Understanding scripts and script steps
      2m 23s
    2. Assigning script steps to buttons
      3m 54s
    3. Understanding the ScriptMaker dialog box
      8m 28s
    4. Creating multi-line scripts
      6m 44s
    5. Adding find criteria to a script
      4m 58s
    6. Understanding the If script step
      8m 36s
    7. Using script parameters
      4m 42s
    8. Reviewing the Send Mail option
      7m 11s
  19. 28m 0s
    1. Understanding script triggers
      2m 41s
    2. Using object-based triggers
      11m 58s
    3. Using layout-based triggers
      7m 51s
    4. Using file-based triggers (Open and Close scripts)
      5m 30s
  20. 56m 42s
    1. Using related fields
      7m 18s
    2. Creating portals and using portal filtering
      10m 38s
    3. Using related fields in calculations
      7m 6s
    4. Understanding multi-predicate relationships
      11m 11s
    5. Using the Go to Related Record script step
      7m 26s
    6. Creating a chart
      13m 3s
  21. 30s
    1. Goodbye
      30s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed FileMaker Pro 11 Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.