What is the simplest custom function with a purpose you can write in FileMaker?
The answer is a custom function with only one character – and that includes the function name and parameters.
The Power of One
My simplest custom function has only a name. And it is the shortest possible name, a single character. The character I choose is the underscore. The function does not expect any function parameters and calculates and returns nothing.
Function _( )
/* no content */
The custom function is so simple I had to add this comment here, otherwise my custom function box would look just odd.
Why is there no content in the function body? Or, a better question, what does the function do?
This function will return an empty string (“”). And this should give you a clue, how to use the function. You can use this function wherever you would use an empty string:
- Check whether fields or variables are empty
- Initialize or ‘delete’ variables
- For Let functions returning nothing (used to set global variables)
- For ‘optional’ parameters in custom function you do not want to fill
- For evaluation expression to avoid excessive use of the escape character
This also explains why I choose the underscore for the name of this custom function. The underscore looks like a placeholder or something empty and therefore resembles best the purpose and meaning of the function.
Example of Use
Compare for empty value:
If( $value = _; ... )
Delete global variables and return nothing from a Let function:
Let( $$counter = _; _ )
Call a custom function with optional parameter and keep that parameter undefined. In this example the function myFunction expects three parameter, but the second and third parameter are optional and do not require any value. I cannot really skip these parameters in FileMaker, but with the underscore I can indicate, I do not assign a specific value to them.
myFunction( "Arnold"; _; _ ) myFunction( "Kegebein"; _; 1 )
Avoid excessive use of the escape character. Without my custom function you would have to use some escape characters. That makes it harder to read and understand the expression.
Evaluate( "Let( $$X = _; _ )" ) //--- Without the custom function: Evaluate( "Let( $$X = \"\"; \"\" )" )
Almost no day goes by without me using this function.