Sometimes you want to make sure that once a user opens a record it remains “locked” until the user is done with it. Unless you as the developer take special measures, the user can close the record and commit the changes simply by clicking on the layout. So how do you do we keep that record open?
In the video above we go through this step by step. Be sure to watch it for all the details. The Demo File is available below. Here is a rough outline of how it is done.
First, we make use of the On Commit Trigger Script Trigger. We have it run a script called “Block Commit.” Under all conditions, this script will exit with a “0” in the Exit Script result. That will cause the Commit Record to fail with an error of 20. The record will essentially be “locked” open. It can’t be committed except for one caveat which we deal with later.
Next, we create another script called “Commit Record Explicitly.” This script will set a variable that $$_AllowCommit to True and then call Commit Record. This is a global variable so it will be available to our “Block Commit” script Then we modify our “Block Commit” script to Exit Script with a “1” if that variable is set to true.
Now our users will not be able to commit the record unless they call the “Commit Record Explicitly” Script. Perfect.
Lastly, let’s deal with the caveat. It happens only with Web Direct. If the user closes the browser tab with our open record in it, the record will be committed despite it being blocked by the script trigger. This is quite clearly a bug. It just shouldn’t happen. I covered this in an earlier blog.
You can get around this by, setting the layout preference of your layout not to save records automatically. Then go back to the Commit Record Explicitly” and edit the Commit Record step so that it can override the layout setting. The final thing you have to do is a total hack. You place a transparent button on the background of the layout so it captures all the clicks that would otherwise cause that dialog to appear.
That’s it now you have a way to lock FileMaker records open until you want to explicitly commit it!
Sample file below.