The Problem
You really like FileMaker's edit-in-place field behavior. Just place a field on a layout and it works in browse mode and in find mode without additional code. It is a beautiful thing but the seemingly random, accidental edits by your users is driving you nuts.
This is a recipe for rolling your own "Edit Mode" feature using the power of global variables in FileMaker 8 or higher. Note: this article in intended to be a quick-start guide, do not rely on this technique to secure your database.
The screenshots below are from a Mac but this tip is platform agnostic.
Download RollYourOwnEditMode.fp7
The general idea
...is to modify the user's privilege set so that record modifications are regulated using a global variable.
Step-by-Step
In this example, I am going to start with a new file. I have defined a table called "contacts with a few basic fields.
Don't worry about the "lock status" field for now; that is an interface bell-and-whistle that I added to give the user some visual feedback. Check out the example file to learn more about that.
Next, I am going to create a basic script to toggle our edit mode. I am going to use a global variable as a switch. I have chosen to name my switch $$__locked
but you could call it whatever you wish. Just make sure it is a global variable because we want to be able access it within this file outside of our script. The script works by setting the global variable called $$__locked
with a value of "1" if it is either "0" or empty at the time the script is run. If it is already set to "1", we are going to flip it "off" by setting it to zero.
Next, I am going to tell FileMaker to check the global $$__locked
before allowing our user to make record changes. Record access is controlled by FileMaker privileges so I am going to go over to the Define>Accounts & Privileges... menu and create a User account with a custom privilege set called "User"...
To configure the record data access setting, I select 'Custom Privileges' from the 'Records' pull down menu of the 'Edit Privilege Set' screen...
I am going to control access to the "contacts" table by highlighting it and changing the 'Edit' privilege to 'limited..." My goal is to use a calculation expression to govern the user's record modification activity.
The calculation is a simple...
not $$__locked
...
FileMaker will evaluate the expression not $$__locked
each time the user tries to modify a record. If $$__locked
is zero or empty, the expression not $$__locked will
evaluate to true (not locked) and the user will get to edit records. If $$__locked
is "1", our expression will evaluate to false and our user will be blocked from making any changes to 'contact' records.
Finally, let's cap it off by attaching a button to our script and by adding a "lock status" calculation field to create a simple indicator of the record lock status.
Cheers!
Ernest says:
"...do not rely on this technique to secure your database."
Now do please pay attention to this comment. Variables lie outside the security schema of the database and are somewhat susceptible to all sorts of interesting manipulations. In some materials to be released soon, I am going to demonstrate a number of these.
So, please do heed Ernest's warning.
Steven H. Blackwell
Platinum Member, FileMaker Business Alliance
Partner Member, FileMaker Solutions Alliance (1997-2007)
FileMaker 8 Certified Developer
FileMaker 7 Certified Developer
Posted by: Steven H. Blackwell | May 20, 2007 at 10:04 AM