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…

Ian Jempson

Ian has an impressive resumé amongst FileMaker developers and is an internationally recognised authority on all things FileMaker and is frequently invited to speak at industry events. In his 15 years of experience he has developed award-winning custom database systems as well as software products that are in daily use by tens of thousands across industries as diverse as investment banking, recruitment, events management, advertising and education In his role as Development Manager, Ian handles our increasing project management requirements. Certified in FileMaker versions 8 through 12, Ian is also well versed in other database platforms which drives him to constantly push the boundaries of what is possible with FileMaker Pro.

More Posts - Website

Leave a Reply