My.ADVISOR.com Sign-In
Username
Password
Sign Up 
Go to Article
Advanced Search 

ADVISOR ANSWERS

Explore FileMaker Pro Set Variable Script Step

Find out when you'd use Set Variable, and what the difference is in variable names starting with $ versus $$.

By Lee Lukehart, Soliant Consulting director of training

UNLOCKED -- This article is provided to subscribers of FILEMAKER PRO BASICS ADVISOR or DATABASED ADVISOR or FILEMAKER PRO BASICS ADVISOR. To subscribe or renew, go to Advisor Store.

Q: I just upgraded to FileMaker Pro 9 from version 7, and am still exploring all the new (to me) features. I discovered one, the script step Set Variable, that is particularly intriguing. I like the idea of being able to create a cubbyhole for a temporary value on the fly, but why else would I use this feature over my old friend Set Field? And what's the practical difference between variable names starting with $ versus $$?

Figure 1: Your options -- Set Variable script step dialog.

A: Congratulations on upgrading! You'll no doubt find many more gems like Set Variable in your exploration. As you now know, this script step lets you create, name, and assign value to a variable all in one step -- without requiring you to create a global field ahead of time. Before FileMaker Pro 8, when script variables were introduced, we had to use global fields to store temporary values for such things as find criteria and loop counters. The most obvious benefit of script variables is the reduction of the number of global fields created for these short-term storage purposes. Variables help cut down on the clutter in the database field list. Variables also provide a key unique capability over global fields; however, that I'll explain in a moment. First, let's review the basic syntax. Here's a snippet of script that finds all records matching the current record, and figure 1 shows the dialog for the Set Variable script step:


Set Variable [$currentPerson;
  Donations::PersonID]
Enter Find Mode []
Set Field [Donations::PersonID;
  $currentPerson]
Perform Find []

As you observed, you can assign variables with the Set Variable script step. As with fields, you have great freedom in naming the variable -- except the name must begin with either one or two dollar signs. It's the shorthand that determines whether the variable is local ($) or global ($$) in scope. Local variables are visible only in the script that set them, whereas a global variable persists after the script ends, and the value it contains can be used by any other script or calculation in the file. By using local variables, multiple scripts could be using what seems to be the same variable -- say, $counter -- but the content of each $counter would be unique to its own script. (This behavior is true even with subscripts, when one script calls another script.) Local variables evaporate when the script that created them ends; global variables disappear when the file closes.

So that's all well and good -- variables are handy and easy to maintain, because they clean up after themselves. However they also possess a particular ability that global fields don't have, with regard to file paths. Extending the example script snippet, let's say you want to save that list of found records for a single donor as a PDF of the printout. You'd likely use the Save Records as PDF script step:

Save Records as PDF [No dialog; "Donations.pdf";
  Records being browsed]

You can name the file whatever you'd like, but you must name the file manually when the script runs or hard code the name in the Output File Path dialog. If you ran this script for another donor, this step would save the file with the same name, overwriting the prior file. This limitation goes away by using script variables! Examine the following two script steps:

Set Variable [$filepath;
  Value: "Donations_" & Donations::PersonID & ".pdf"]
Save Records as PDF [No dialog; "$filepath";
  Records being browsed]

This script dynamically names the saved PDF files, embedding the (presumed unique) PersonID in the file name. You could, in short order, write a script that saves specifically named files for each donor in the database. Note that just naming the file with no additional file path information results in the file being saved to the same folder as the FileMaker Pro file that saved it -- which may not be the most desirable location. For more control, construct a file path string using relative (e.g., file:../filename) or absolute (e.g., file:/C:/foldername/filename) file path naming conventions. Use functions such as Get(DesktopPath) or Get(DocumentsPath) to easily save files to the user's desktop or documents folder, like this:

 Set Variable [$filepath;
  Value: Get(DesktopPath) & "Donations_" &
    Donations::PersonID & ".pdf"]

There are a few other things to know about script variables:

  • Like a field, you can freely use variables in calculations.
  • You can also create local and global variables in the Let function. This function could already set variables, but whose scope is limited to the function itself (see the FileMaker User's Guide for details on the Let function).
  • Unlike global fields, you can't use variables to define relationships.
  • Like global fields, in multi-user hosted databases variable values are unique to each user session. Two users could both be using the $$faveColor variable, for example, and it would hold that particular user's choice.
  • Variables can hold content corresponding to FileMaker Pro's field data types: text, number, date, time, timestamp, or container. The data type of a variable is set dynamically, based on the assigned data.
  • The Set Variable script step is Web compatible.

Explore Set Variable Script Step

No reader comments ... yet.

    What do YOU think about this topic? Share your advice and thoughts using this form.

    Your Name

    REQUIRED : PUBLIC

    Your E-Mail

    REQUIRED : PRIVATE

    Job, Company

    OPTIONAL : PUBLIC

    City, State, Country

    OPTIONAL : PUBLIC

    Your Web Site

    OPTIONAL : PUBLIC

    Your Comment

    Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


    Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

    Lee Lukehart is director of training for Soliant Consulting, an FBA Platinum Member. Lee is a FileMaker authorized trainer, Developer Conference speaker, and FileMaker 7/8/9 Certified Developer -- and was juggling data even before he caught the FileMaker bug in 1986.

    Printer-friendly
    page layout

    Keyword Tags: FileMaker, FileMaker FileMaker Pro, FileMaker Users

    ADVISORAMA
    Learn from yesterday, live for today, hope for tomorrow.

    ARTICLE INFO

    FileMaker Pro Basics Advisor

    Web Edition: 2008 Week 08, Doc #19385

    Print Edition: Issue #13, Page 5

    SUBSCRIBER ONLY ARTICLE LOCKED

    Subscribe to FileMaker Advisor Magazine

    Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.

    FileMaker.Advisor.com

    Subscribe to Advisor Basics of FileMaker Pro

    Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!

    FileMaker.AdvisorBasics.com

    Free E-Newsletters

    Keep up! Hot News, How-To, Tips & Tricks, Expert Advice, and more. Click to request your's free.

    AdvisorUpdate.info

    Need Know-How Now?

    What direction are you going with your business? Advisor Guides are packed with the answers you need to work smarter. Can you afford to fall behind?

    AdvisorStore.com

    Showcase Your Smarts

    Submit your tips, techniques and advice and let Advisor promote your business and build your career. Show the world what you know!

    AdvisorTips.com

    Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
    Portions copyright ©1983-2008 Advisor Media, Inc. All Rights Reserved.
    Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
    ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, Inc. in the United States and/or other countries.
    Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
    lukel002-02 posted 02/18/2008 modified 05/12/2008 03:43:43 AM ztfmfu/ztfmfu
    domino-144.advisor.com my.advisor.com 05/16/2008 12:21:22 PM