FileMaker: More Useful Date Fields

Filemaker’s date field is not very kind to users…

…especially ones that like to type instead of using their mouse to select a date. However, we can fix this to make a more pleasing user experience.

If a user wanted to enter in “10” for the date, with the logic that “10” is the day of the date of the current month, they would be prompted with this error:

Image

It is a little more wordy than it needs to be, as it should simply say, “Please re-type your entry in MM/DD/YYYY format.” We can avoid this problem all together by adding in a script trigger to our field, but first we need the script to trigger.

What we want to do is make a script that will convert the input of “10” to “5/10”, a valid input for the date field.

Create the following script and name it “Date Field Auto Fix”:

Set Variable [$fieldname; Get ( ActiveFieldTableName ) & "::" & Get ( ActiveFieldName )]
If [ Length ( GetField ( $fieldname ) ) < 3 ]
  Set Field By Name [$fieldname; ( Month ( Get ( CurrentDate ) ) ) & "/" & GetField ( $fieldname )]
  If [ GetField ( $fieldname ) < Get ( CurrentDate ) ]
    Set Field By Name [$fieldname; ( Month ( Get ( CurrentDate ) ) + 1 ) & "/" & Day ( GetField ( $fieldname ) ) ]
  End If
End If

Next we’ll want to apply this new script to a script trigger on our field. The type of script trigger we should use is OnObjectValidate. 

Image

This will run our script before validation happens, fixing our date input, so FileMaker will be happy with the results and we won’t see the standard date field validation error.

Leave a Reply

Your email address will not be published. Required fields are marked *