Another nice new feature in FileMaker Pro 13 is the set of Base64Encode/ Base64Decode functions. Base64 encoding is a method of representing binary data (for example a .png icon file) in an ASCII string format (suitable for pasting into scripts or calculation fields). This new set of functions have the potential to eliminate extraneous Global container fields in your database solutions.
One reason to consider using this technique is the possibility of adding calculated icons to a database solution simply by adding a script. With this technique, there is no need to add global fields to store the icons. Sometimes it is necessary to add a set of User Interface icons to a production system, which would require a lengthy set of tasks:
- asking all Users to close the database
- close the Database file
- take the Database offline
- open the File in FileMaker Pro
- add the icons to a set of Global Fields
- reupload the Database file to FileMaker Server
- reopen the Database file
- reinvite Users to open the file
Instead developers can now simply paste a fairly portable and reusable script with the requisite icons Base64 Encoded into the file, add the icon field to the data table and modify the script to accept this field.
“Look Ma! No Global Fields!”
Download Icon Collection Demo file here. Just to be clear, the Icon Collection portion of the demo is just to give you some icons to experiment with. The idea of the technique is to build a portable script and paste it into your other solutions.
Sample Icons with BaseEncoding
The demo file contains a set of sample icons. You can add your own icons to this file, or created your own version using these techniques.
Calculated Base64Encoded and Base64Decoded fields
Add two fields to the icon database table: One to encode a container field as Base64Encode and the other to create a calculated Base64Decode field, the text of which can be copied and pasted straight into your scripts.
- Base64Encode ( Icon )
- “Base64Decode ( \””&Base64Encoded&”\”, \””&Right( File Name; 4 )&”\”)”
Note that the Decode function requires a file name to function correctly and that file name needs the appropriate file type extension. If it is not there, the graphic image will not display correctly.
Conditional Formatting to highlight files without a name extension
Conditional formatting is used to highlight offending records. Alternatively, this could be scripted into a dialog box in the Copy Base64Decoding routine.
Calculation to catch fields without a name
There other ways to do this, but here a cumulative pattern count is used to detect an appropriate file ending.
PatternCount(Icons::Base64DecodedString; “.jpg”) +
PatternCount(Icons::Base64DecodedString; “.jpeg”) +
PatternCount(Icons::Base64DecodedString; “.tif”) +
PatternCount(Icons::Base64DecodedString; “.tiff”) +
PatternCount(Icons::Base64DecodedString; “.png”) +
PatternCount(Icons::Base64DecodedString; “.gif”) = 0
File Name extension
In a correctly named icon field, the file extension will show up in the Base64Decoded field.
Check Uncheck buttons
Script to toggle buttons
This sample script demonstrates a very simple toggle script, using the Set Field script step to set a container field to the Base64Decoded text we generated in the Icons table. This script could be made even more portable by setting a variable with the field name and then using Set Field by Calculation. That way, there would only be one script step to alter when pasting into a new solution.
Calculated Base64Decode field setting by calculation
Note that no global fields are required as the icon has been reduced to a lengthy text chunk. This text chunk was copied from the Icon Collection Base64DecodedString field.
Toggle Checkbox OFF
Toggle Checkbox ON
Using FileMaker Pro 13’s new Base64Encode/Base64Decode functions, we can lighten the database load of global fields and add useful User Interface features to a database on the fly, by simply pasting in a portable, reusable script and targeting the appropriate container field. This same basic technique could be used on calculated fields as well, so rather than scripting the toggle, it is built into the field definition (If Condition X is met, display Base64Decoded text A, else display Base64Decoded text B).
FileMaker Geek CONTAINER FIELD IMAGES IN THE WEB VIEWER