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

ADVISOR ANSWERS

Update FileMaker Pro Value Lists Without Scripts

Say you use a value list to add products to an order. How do you get the value list to change so after you add an item to the order, it disappears from the value list? Find out here.

 Subscribers: Sign-in to activate download link -- Download an example file demonstrating this technique.
By Chris Moyer, The Moyer Group CEO and FileMaker Advisor technical editor, and Bob Bowers, Soliant Consulting CEO and FileMaker Advisor technical editor

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

Q: I use a value list to add products to an order. How can I get the value list to change so after I add an item to the order, it disappears from the value list? Any calculations I add to the products table to get this idea to work make the value list stop working completely. Can it be done?

Figure 1: Value list – It's essential that your value list use the newly created "Customer to Order to Products by Unordered Products" relationship and that it does so from the context of Customer to Order.

A: There are several ways to do what you're trying to do here. In our opinion, the simpler the technique, the better. Also, if you can do it without the use of a script, that technique has more finesse than brute force scripting.


Let's start by reviewing the structure of the system. You have an Order table, which is related to an Order Item table by Order ID. Order Item is related to Product by Product ID. For simplicity, we're going to consider your case which allows for creation of related Order Item records through the portal. The goal is to get a value list that displays all products that aren't on the current order.

If you try to construct a calculation in the Product table to display or not display the product ID based on related Order Item records, that calculation will be unstored and so won't be usable for purposes of creating a value list (which requires index-able values). If you try to create a script that takes the current order ID, switches to the Product table, then replaces a stored Product ID Display field with the Product ID based on whether related Order Item records match the current Order ID, you'll get values you can index, but the script will run slowly if you have lots of product records, and it won't work in a multi-user environment because different users running the script at the same time will overwrite each other's replaced values. Therefore, you need a solution not based on calculated values in the Product table.

What you can do is create a calculation in the Order table that gives a return-delimited list of the Product IDs currently on the order. There are a couple of different approaches, but the simplest is to use the List function. You'll get a list of the IDs you're looking for if you add a calculation field called z_Prod_IDs_On_Order with this formula:

List ( Customer to Order to OrderItem to Product::_Product_ID )

If you then create a new relationship from Order to Product matching on this field to the Product ID field and setting your join operator to ?, you can create a value list of related values starting from the Order table (figure 1).

This technique works fine if you have at least one item on your order, but it doesn't work for orders without any order items -- no items will appear in your value list. You can fix this issue by changing the calculation slightly:

Case ( Length ( List ( Customer to Order to OrderItem to Product::_Product_ID ) ); List ( Customer to Order to OrderItem to Product::_Product_ID ) ; "0" )

Now the field returns 0 when no items are on the order, and presuming no products have 0 as their Product ID, the resulting value list displays all products.

But does this approach work as expected? If you add a product to the order, then try to add another, you still see the added product in the value list, yet the calculation field shows the product ID as one of the products on the order. If you open the Manage Database dialog, close it, then try the value list again, it works properly. What's happening is that FileMaker Pro caches the join results, which is a fancy way of saying it remembers the related portal rows for longer than you'd like in this case.

You can overcome this last difficulty with a simple script we'll call Add Product that contains the following steps:

Refresh Window [Flush cached join results]
Go to Field [Customer to Order to OrderItem::_Product_ID]

The Refresh Window step is key because it forces FileMaker Pro to re-evaluate the portal and yield the correct values in the value list. The Go To Field step is there because this script gets attached to the _Product_ID field in the portal, and you have to put the user into the field to trigger the value list. After you've defined the field to be a button that performs this script, all will be well. Subscribers can download an example file demonstrating this technique.

Update Value Lists Without Scripts

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.

    Chris MoyerChris Moyer is president and CEO of The Moyer Group, a FileMaker Pro consulting and training firm with offices in Atlanta, Chicago, and San Francisco. Chris is a technical editor of FileMaker Advisor Magazine.

    Robert BowersBob Bowers is CEO of Soliant Consulting, and co-author of three books on FileMaker Pro, including Special Edition Using FileMaker Pro 7. Bob is one of a handful of trainers authorized to teach the FileMaker Professional Foundation Training Series. Bob has been a speaker at several FileMaker Developer Conferences, and was awarded the FileMaker Fellowship Award in 2002.

    Printer-friendly
    page layout

    Keyword Tags: FileMaker, FileMaker Development, FileMaker FileMaker Pro

    ADVISORAMA
    Relationships with coworkers can be fraught with consequences.
    -- Capt. Jean-Luc Picard, Star Trek: The Next Generation

    ARTICLE INFO

    FileMaker Advisor

    Web Edition: 2008 Week 04, Doc #19360

    Print Edition: February/March 2008, Page 7

    SUBSCRIBER ONLY ARTICLE LOCKED


    File: Download an example file demonstrating this technique.
    Subscribers, log-in for Download link.

    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

    Secrets Of The Top Experts -- Now!

    See exactly how to do it, step-by-step, in Advisor Academy CDs created by the top experts. Click to see what you can learn right now.

    AdvisorAcademy.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.
    moyec073-03 posted 01/21/2008 modified 05/12/2008 03:44:40 AM ztfmfd/ztfmfd
    domino-144.advisor.com my.advisor.com 05/16/2008 12:15:17 PM