People Goal 5 - Part 1: Learn about scripting

Document created by Kedar on Feb 4, 2015Last modified by communitymanager on May 12, 2015
Version 11Show Document
  • View in full screen mode


Let’s cover some important scripting concepts before you get started: the scripting environment, script steps, and scripting strategies.


The scripting environment


FileMaker Pro’s Script Workspace is your environment for creating and editing scripts. Goal 5 of the Learn tutorial introduced you to scripts and the Script Workspace, but if you want more detailed information, please click here.


A script is a sequence of linear commands (known as script steps), which you put together either through a point and click interface or by entering them via the keyboard. Then you give the script a name, save it, and refer to this name when you want the script to be performed.

There are a number of ways to perform a script. Most scripts run as the result of user interaction with your solution, such as clicking a button. Here are some of the possibilities:


  • Selecting them from the left pane of the Script Workspace and clicking the Perform button

  • Listing them in the Scripts menu where users can select them

  • Causing them to be triggered by certain events, such as opening a new window or changing a specific field

  • Customizing FileMaker menus to include menu items that run your scripts

  • Scheduling them to run automatically on FileMaker Server




Script steps


Scripts can perform many standard actions, much like a user interacting with your solution. These include navigating from layout to layout, entering data, and performing finds. Here are some examples:


  • Go To Layout

  • Set Field

  • Perform Find



They also can “think” and control the process, similar to a user making decisions such as whether to perform specific actions, repeat actions, pause, or stop completely. All the script steps relevant to decision-making appear in the Control group in the right pane of the Script Workspace. Here are some examples:


  • If / End If

  • Else

  • Loop / End Loop

  • Exit Script

  • Halt



Finally, they can do some things that a user can’t do directly, such as calling another script based on a timer, inserting content from a website URL, or executing a SQL command. Examples include:


  • Install OnTimer Script

  • Insert from URL

  • Execute SQL



There are over 130 script steps in total, but you don’t have to learn all of them at once. This training will teach you some of the basics. If you are interested in learning more, we recommend reading FileMaker’s Script Steps Reference.




Scripting strategies


The subtleties of scripting will probably take you some time to master.  They are best learned through practical experience and experimentation, as well as by analyzing existing scripts to see how they work. We recommend that you have a look at the scripts in the Starter Solutions as a point of departure.


One useful tool is the Script Debugger (available only in FileMaker Pro Advanced), which allows you to perform scripts step by step while watching what happens. It’s primarily used as a troubleshooting tool to identify problems, but it’s also a great way to learn about scripts in real-time, exploring what each step does and how it affects the solution.


When writing scripts, always follow these four key principles:


  • Have a goal in mind

    Any time you write a script, you should have a clear understanding of the intended outcome. For instance, you might say, “I want a user to click this button and, without any further interaction, generate a sales activity report that is ready to be printed.” Once you clearly define the desired task of the script, what remains is figuring out the sequence of steps required to produce the result.



  • Use trial and error

    Don’t be afraid to learn through trial and error. It can be difficult to predict exactly what will happen when you combine a set of script steps in a particular way. When in doubt, run the script and look at the results. If you see that it does not work, then try something else, learning from your mistakes along the way.



  • Protect yourself

    Be very careful, however, about experimenting with your file once it is in use by your business. Consider performing your tests in a copy of the file instead. Even during the development process, duplicate your file frequently so that you can go back to an earlier version in case something goes wrong that you don’t know how to fix.



  • Test thoroughly

    Test your scripts under all foreseeable conditions. Many of the scripts you write will be triggered under varying circumstances, and you will want to be confident that the script will work in all contexts. You might wonder, for instance, what will happen when the script is run in a multi-user environment, or when it is used by someone with a particular level of security. Many of the bugs associated with script writing involve the failure to anticipate a particular set of conditions.