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

ADVISOR TIPS

Understand FileMaker Pro Record Locking

Understanding all aspects of record locking is extremely important to producing a professional FileMaker Pro solution. Find out what you need to know.

By John Mark Osborne, Database Pros president and owner, 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.

I teach a lot of FileMaker Pro courses and I'm always surprised at the large number of experienced developers who don't consider record-locking issues in their development. Usually they've heard about the concept but don't know how to replicate a record-locking issue, let alone test for a record-locking error in a script. Understanding all aspects of record locking is extremely important to producing a professional FileMaker Pro solution.

I'll start by defining record locking. Record locking occurs when two Guests try to access the same record at the same time. In FileMaker Pro 6 and older versions, a Guest could take control of a record simply by clicking into a field. Subsequent Guests attempting to access the same record receive a message that someone else is modifying the record. The record will remain locked until the first user releases the lock by exiting all fields. Exiting all fields could occur by typing the Enter key on the keypad, clicking outside the fields, changing records, or changing layouts, just to name a few. The only difference with FileMaker Pro 7 and newer versions is record locking doesn't occur until a Guest starts modifying a record. In other words, someone has to start typing into a field on the record.

Now that you understand record locking, the next step is to learn how to test for record locking without setting up a Host computer, copying your solution to the Host hard drive, and sharing it via FileMaker Server. This might not seem so difficult until you realize you have to copy a new version of the solution to the Host each time you want to test a new version of the solution. An easier approach, and the only approach if you only have one computer for development, is to open your solution in regular FileMaker Pro and turn on sharing. You'll find the FileMaker Network menu choice underneath the Sharing sub-menu under the File menu. When the resulting dialog appears, turn on network sharing and make sure the file you are testing allows access by all users.

After you have file sharing enabled, the same computer acts as Host and Guest. Just choose Open Remote from the File menu. In the resulting dialog, locate your computer under local hosts. Open the solution you want to test for record locking and a second occurrence of your file appears, using the same name in the title appended with "-2" and the name of your host. Now you're ready to test record locking. In either window, click into a record and begin typing. Without exiting the record, switch to the second window and attempt to modify the same record. You'll receive an error message telling you it's being modified.

The standard error message FileMaker Pro generates when two Guests attempt to manually modify the same record works fine. Only when you incorporate scripting into your solution does record locking require your supervision. Any time a script attempts to modify a field on a record, such as what occurs with Set Field, Insert Calculated Result, and many other script steps, you must make sure the current Guest has control of the record or else the record may not be modified. Rather than trying to modify the record and then test for an error, you're better off trying to gain control of the record without modifying it using the Open Record/Request script step. For instance, the following script shows the basic construct for a record-locking-aware script:

Set Error Capture [On]
Open Record/Request
If [Get(LastError) = 301]
   Show Custom Dialog ["Record Locked"; "This record is locked!"]
Else
   #Place any script steps here you want to occur if the record is open
End If

Briefly, the Set Error Capture script step hides any error message dialog that might appear, such as the record-locking error. The Open Record/Request script attempts to gain control of the record. If the record is locked (being modified by another Guest), an error of 301 will result. If no error occurs, the script locks the record for the current Guest and can safely modify the record. As an aside, you can release a locked record using the Commit Record/Request script step.

Testing whether the current record is locked is simple, but the task gets significantly more complex when attempting to modify multiple records. For example, the Replace Field Contents script step or a record looping script attempt to modify multiple records in succession. If you have a few Guests on the network, chances are the modifications will occur without a hitch. When you start to add more users, the chances that one or more records are locked increases.

So, what can you do in this record-locking scenario? There are complicated transaction techniques you can employ, but I like to tailor the solution to the need. For instance, say you want to mark all the records in the found set so you can search for the marker and reconstitute your found set at a later date. Of course, this process could cause record locking on more than one record, which you could attempt to track. Instead of writing a value to the records, grab the serial number from each record. Reading a value from a record doesn't require it to be unlocked. In this way, you can gather all the serial numbers and store them in a return-separated list. To restore your found set, simply use the serial numbers in a multi-key relationship along with the Go to Related Record script step. Although this is a brief overview of the technique, you get the idea. For every record-locking scenario, there is usually an alternative approach.

Understand Record Locking

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.

    John OsborneTechnical editor John Mark Osborne is president and owner of Database Pros, offering FileMaker resources on the Internet. He is author of Scriptology, a speaker at FileMaker Developer Conferences and Macworld conferences, and a trainer for the Professional Training series created by FileMaker, Inc. http://www.databasepros.com jmo@filemakerpros.com

    Printer-friendly
    page layout

    Keyword Tags: FileMaker, FileMaker Development, FileMaker FileMaker Pro

    ADVISORAMA
    Anger is a thief who steals away the nice moments.
    -- Joan Lunden, TV host

    ARTICLE INFO

    FileMaker Advisor

    Web Edition: 2008 Week 05, Doc #19364

    Print Edition: February/March 2008, Page 36

    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

    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.
    osboj037-04 posted 01/28/2008 modified 05/12/2008 03:43:58 AM ztfmfd/ztfmfd
    domino-144.advisor.com my.advisor.com 05/16/2008 12:31:17 PM