Writing modular code in FileMaker.

FileMaker 11 has provided us with some new  options when it comes to code reuse. This blog entry shows a simple example of how we can write modular reusable code.

Why do we want to re-use code? The short version is that it gives us better quality code in a quicker time. Further, if it’s written in a properly encapsulated way it allows us to implement new behaviours quickly across all areas that use the code.

Our example is going to be a simple one, to allow the user more options for entering dates. We’re going to provide short cuts to enter the dates for different dates. The user can enter one of the following: today, tomorrow, + or – any number of days.

The script is called using the OnValidate script trigger, which is new in FileMaker 11. It uses the Set Field by Name script step and the three functions get(ActiveFieldTableName),  get(ActiveFieldName) and get(activeFieldContents).

Here’s what the script looks like:

This script once written can be called on any date field in your system. This technique can obviously be easily extended to use other shortcuts as well. For example it’s trivial to extend it to accept +1w to increment in weeks rather than days. This is left as an exercise for the reader. I’ve always wanted to say that!

Here’s a sample file…

Simon Ward

Simon has been developing FileMaker databases since the late 90s and joined Linear Blue in 2006. Over this time he has developed database systems for clients in many different industries from Order Processing to Book Publishing. Simon’s BSc in Chemistry from Thames Valley University comes to the fore in his analytical skills and he is certified in FileMaker versions 7 through 12.

More Posts - Website

Leave a Reply