Modern Commitment

Have you ever wanted to prevent a record from being committed when a user clicks on the layout? There are various reasons you might want to do that. In my recent scenario, I wanted to allow users to create records in the Request table, but not view or edit them. I set up my security like so:

This setup functions as a sort of drop-box — in the Request table, users can create a record, but that’s all. They can’t go back and look at their data or that of other users. Note: the user can enter and edit data in fields, as long as the record has not yet been committed.

The one problem with this is that if a user accidentally commits the record they’ve created, for example by simply clicking on the layout outside a field, they will lose the ability to edit or even view the layout they were just working on.

So, we need a way to prevent an accidental commit. Here’s a clean and simple method to handle it. All it takes is one simple script, assigned to a layout trigger.

First, let’s create the script. The script will be triggered when the record is committed — i.e. using the layout’s OnRecordCommit trigger. This trigger runs before the action happens, and like all such triggers we can stop the action with the script command:

Exit Script[ Text Result: False ]

That’s essentially the whole script. But we don’t want every commit to be stopped. We want to allow commit when the user clicks the Submit or (maybe) the Cancel buttons for example. That means we’ll need to use some kind of branching logic, so let’s pass a parameter into the script and act on it:

Set Variable[$param ; Value: Get(ScriptParameter) ]
If[ IsEmpty( $param ) ]
  Exit Script[False]
End If

What should we use as the parameter? An elegant method is to simply use Get(ScriptName). That way your buttons can still have their own parameters. (Credit to Daniel Wood and this article for demonstrating this technique.) Note: your button action must be Perform Script, it can’t be Single Step.

Now we’ll go into the Layout Options and assign our new script. Save record changes automatically should be enabled on the General tab.

On the Script Triggers tab we select our script, which I’ve named Stop trigger, and specify the parameter:

The logic when you accidentally commit is:
– the OnRecordCommit script will trigger
– the parameter is empty, since there was no script running
– the script exits ‘False’
– the commit fails
– you can still edit fields

The logic when you commit using a button is:
– the button’s script commits the record
– the OnRecordCommit script will trigger
– the parameter is the name of the script attached to the button
– the button’s script continues

That’s it! This works in FileMaker Pro, WebDirect, and FileMaker Go.

Download the example file to see it in action.

There are other ways to control data entry — via global fields, or the web viewer background trick — but I really like this triggered method.

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.