Must-Have FileMaker Custom Functions

Must have custom functions

Over the course of its development, a FileMaker custom solution takes on many shapes. Its schema grows, shrinks, twists and bends to fit the needs of its design. Keeping the design of the solution simplified is a challenge, but ultimately leads to a good foundation for a developer to stand on. To aid with this simplification, FileMaker offers a powerful tool for the developer’s toolbelt: custom functions.  Custom functions are as you would expect - they are FileMaker functions that are custom defined by the developer and can do anything the developer programs them to do. Our Custom Functions videos go into detail about five different types of custom functions that you, as a developer, can utilize in your solution.  

Take a look at our Must Have Custom Functions video series to learn more about what custom functions can do to simplify and streamline your development work. 

Part 1- Fields and Parameters  

Our first Custom Functions video covers using custom functions to handle field and parameter data. One such function is “GetNamedValue”, which provides the value belonging to a key-value pair’s key, when given a list of key-value pairs.  

This is quite handy when you are passing lots of different data through a single parameter from one script to another and want to ensure you get the right one. 

We have made use of this function in conjunction with another pair of custom functions: Compress and Expand. The Compress custom function takes the new line character (commonly called “pilcrow” or “carriage return”) and replaces it with the special character called “no-break space” that looks like a space character but is functionally distinct. The Expand custom function does just the opposite, returning that non-breaking space character back into its original pilcrow state. When used together, the Compress and Expand custom functions help protect against value-based parsing errors that would arise when passing data that contains multiple lines. This is quite handy! 

TestSpacer

Part 2 - Text Cleanup 

In the second Custom Functions video, we cover numerous text formatting custom functions that show great promise in cleaning and preparing text data for any use in the solution. A custom function like FullTrim would ensure that any user-generated text data will be clean of extra space characters as well as any pesky newline characters at the beginning or end of the text string, and the RemoveEmptyValues function is perfect for condensing a large list of values that may contain numerous empty values into just the valid data that you want. 

In many of our custom development projects, we’ve gone a bit further with the RemoveEmptyValues and transformed it into a custom function called “UniqueValues”, which leverages the power of recursion with simple logic tests to take a return-separated value list and clean out any empty or duplicate values from it, resulting in a neat, clean, formatted list of non-repeating text values just ready for comparison or parsing. 

TestSpacer

Part 3 - Platforms and Devices 

The Platforms and Devices video provides several quick and easy shortcut custom functions that give platform-dependent scripting more flexibility. Functions such as PlatformWin, PlatformMac and PlatformMobile make it easier to recognize the different operating systems that FileMaker can run on, by wrapping up the Get(SystemPlatform) native function in a clean package and making it easier for a developer to interpret what the different return values mean. The same logic can also be applied to the DeviceIpad and DeviceIphone custom functions, as they simplify the Get(Device) native function for working with mobile devices. 

Platform-specific and device-specific custom functions like these are indispensable for working with multiplatform solutions. If your solution is designed to be deployed for desktop versions of FileMaker but users can be working on Windows or Mac, these custom functions make it easier to differentiate in scripts between which environment. Server-side scripting through the Perform Script on Server process also benefit, as solutions should, generally, have some logic in their Open script to detect whether the environment is a server platform. That way, the solution can simply get to the right context as per the workflow’s needs instead of setting up global variables, layout contexts and so on that are required for client-side runtime. 

TestSpacer

Part 4 - Date and Time 

Our fourth video discusses both simple and complex custom functions designed to format and prepare date, time and timestamp values for use in the FileMaker solution. The Today custom function makes a comeback from the old days of FileMaker past and simply returns the current date, while the UTCTimestamp custom function works overtime by converting a provided FileMaker native timestamp to a UTC timestamp based on the time zone value (either current or as defined in a time zone field).  

With the growing power of integrating RESTful and online APIs into FileMaker in recent events, custom functions provide more power to the preparation of data that these APIs are contingent upon. The FileMaker Admin API, for example, requires any date or time values to be a strict format. We have designed a custom function called “FMDateToAPIDate” in our FM Server Manager solution that takes a native FileMaker date and performs all the appropriate conversion and parsing to make it into an acceptable API date string that the Admin API requires. Doing so saves plenty of time in writing the scripts, as it has reduced several script steps or repetitive calculation definitions down into a single custom function. 

TestSpacer

Part 5 - Random Fun

The final video in our Custom Functions series goes into more whimsical territory by working with the Random function. On its face, the Random native function generates a decimal value between 0 and 1 exclusive, but it leaves a bit to be desired. What if we want it to go between 0 and 100? - 50 to 50? With the custom function RandomInteger, you can generate a random whole integer between two different number values, no matter how far apart they are.  

We’ve made use of the Random function and, more specifically, the RandomInteger custom function for setting up vast amounts of sample data for testing and validation of our many software products. Using random number generators like RandomInteger makes it a cinch to spit out huge record sets, picking randomly from numerous list variables to set up somewhat reasonable details about anything from customers to invoices to item values and more. The random nature of the test data also proves quite useful for both positive testing and negative testing of a solution when live data is just not an option. 

TestSpacer

Additional Training and Resources

If you are interested in additional FileMaker videos, training courses or product news, please