Feature flags are a powerful technique used in software development to enable or disable certain features within an application. They provide developers with the ability to control the availability of specific functionalities at a granular level without the need for frequent code deployments.
In Claris FileMaker Pro, feature flags are a great way of isolating script code from users during development and testing. This article uses a global variable to store a carriage return-delimited list of feature flags that are currently enabled.
But First, a Custom Function
First, write a custom function, named
env.featureFlag, with the following code:
This is a very simple custom function. The
env.featureFlag function does not require any parameters. It retrieves the list of enabled feature flags from the
$$~listFeatureFlags global variable.
Why Use a Custom Function instead of the Global Variable?
Using a custom function makes checking which feature flags are active more flexible and easier to maintain. For example:
- When writing calculations that reference the feature flags list global variable, custom functions can be referenced in the calculation editor through auto-complete and the functions list. This reduces the chance of errors due to mistyping or misremembering the variable name.
- If the feature flags global variable name is changed in the future, only the custom function needs to be updated rather than every script that references the variable.
Make Sure These Two Custom Functions are Installed
Some of the following scripts require one or both of these custom functions. If you don’t already have them, please copy them from our demo file into your solution before proceeding.
To use Feature Flags, create two new scripts for toggling flags on and off.
Enable Feature Flag ( featureFlag )
These scripts take the name of a feature flag and add (enable) or remove (disable) it from the
$$~listFeatureFlags global variable.
Specific Feature Flag Scripts
Next, create 2 scripts for each feature flag. One will enable the flag. The other will disable the flag. Here is an example of each script for a feature named,
ENABLE: New Feature ( newFeature.v1 )
With these two scripts, this new feature can be turned on or off using a number of methods, including:
- a start-up script which toggles new features on or off when the file is opened
- attach the script to a button which can be shown/hidden depending on the user’s administrative privileges
- call the script from within other scripts
The options are almost endless.
Now it’s time to incorporate feature flags into scripts where you want the to conditionally use the new feature.
Within a script that will use the new feature, use the
If script step with the following condition:
- Replace “newFeature.v1” with the name of the feature flag you want to check.
- The “list.hasValue” function checks if the specified feature flag exists in the enabled feature flags list.
By incorporating this code snippet into your scripts, you can selectively execute certain actions based on the status of a feature flag. This provides you with a convenient way to control the behavior of your FileMaker Pro solution dynamically.
When using feature flags in FileMaker Pro, keep these considerations in mind:
- Feature Flag Naming: Use descriptive and intuitive names for your feature flags to ensure clarity and ease of understanding.
- Flag Management: Maintain a centralized and well-documented list of feature flags and their purposes. This will help ensure consistency and simplify future updates.
- Testing and Validation: Before deploying your solution, thoroughly test each feature flag to verify its functionality and intended behavior. This is crucial to avoid unintended consequences or conflicts with other parts of your application.
- Communication and Collaboration: Communicate the purpose and status of feature flags effectively with your users, especially users who will get the new functionality. This promotes collaboration, enables seamless integration of new features, and ensures everyone understands the current state of the application.
Feature flags offer FileMaker Pro developers a flexible and efficient way to manage the availability of specific functionalities within their solutions. With the
env.featureFlag custom function, controlling feature flags becomes straightforward, allowing you to adapt your application’s behavior without complex conditional logic or frequent code deployments. By leveraging this technique, you can build more adaptable and dynamic FileMaker Pro solutions, providing a better user experience and facilitating agile development practices.
Remember to use feature flags judiciously, maintain clear documentation, and conduct thorough testing to ensure a smooth implementation.
Note: The Feature Flag methodology outlined in this article was introduced at Codence by Cristos Lianides-Chin.
Mack has 20+ years of experience with both Claris FileMaker and Web Application development, and is joining Codence as Application Developer all the way from Rural Hall, North Carolina. When not experimenting with Claris FileMaker or some new web design do-dad, Mack loves to roam flea markets and yard sales to feed his lifelong obsession with Comic Books (and everything that’s Comic Book adjacent).