A particular approach to using FileMaker’s “LET” Statement

As FileMaker makes great steps to help us type our scripts faster inside the script space editor, the “LET” function still presents itself as one of my favourite functions to use.

Why?

Because it allows you to write a lot of logical evaluations in one easy-to-update section. Yes, it can be argued that this approach is dangerous because it places a lot of logic into a single FileMaker script step that can easily be accidentally deleted. With that disclaimer out of the way, here is why I like using this approach.

#1. Set Native FileMaker Variables

You can use it to set up native FileMaker variables ($local and $$global). Which was a huge revelation when I discovered that I can type a lot of my variables inside a single “SET VARIABLE” script step. This has become my favourite way to set variables for a single script. Mind you, this is only truly helpful if you have a need to set a lot of variables within a single script. If you only need to set 5 or less, the traditional approach to setting FileMaker variables is probably a better approach.

Let (
[
$var1 = table::field01;
$var2 = table::field02;
$var3 = table::field03;
$var4 = table::field04;
$var5 = table::field05;
$var6 = table::field06;
$var7 = table::field07;
$var8 = table::field08;
$var9 = table::field09
];
“”
)

#2. Quickly Stack Variables

You can quickly stack the same variable within the same “LET STATEMENT” to help evaluate a single piece of logic without nesting your evaluation logic. I find this makes the readability of the evaluation easier and it helps add overriding logic.

~PIECE_COUNT = Sum ( table::fieldvalue01 ) ;
~PIECE_COUNT = Round (~PIECE_COUNT ; 0);

~COUNTRY = Upper (table::fieldvalue02) ;

~COUNTRY = Case (~COUNTRY = “CANADA” ; “CA” ;
~COUNTRY = “CA” ; “CA” ;
~COUNTRY = “UNITED STATES” ; “US” ;
~COUNTRY = “USA” ; “US” ;
~COUNTRY = “US” ; “US” ;
“ERROR – Missing Country Parsing Logic”
)

#3 Store the Syntax in a Text File

You can store the syntax in a text file and maintain it using your favourite code editor. How useful is it to be able to do this? I’m still working on figuring this out. For now, it’s just kinda cool to see some of the syntax elements auto-colour-code as per the image below.

Summary

I use this approach in all my solutions where the need arises. I have heavily used this approach three times now and it has worked well each time.

The most recent iteration has been the best. The overall code base was kept small and making updates to it is very easy. The only annoying part is that copying tabbed spaces between FileMaker and other apps is not consistent and tabs do not render the same. If anyone has a tip to help alleviate this annoyance, I am all ears.

Hope this peaks someone’s interest. I’m curious how many others use this approach.

Here is a quick video of my latest iteration of this approach. This is how it looks when viewed via the Visual Studio Code editor.