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.
Demo buttons

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).
Related Posts
FileMaker Progress Indicators using a Web Viewer and Animated GIFs
FileMaker Geek CONTAINER FIELD IMAGES IN THE WEB VIEWER
hi douglas, that’s a really nice idea!
one think which strokes me is: what “weights” more, the icon (let’s say 12kb) or the encoded text?
Good question. My tests suggest that the Base64 encoded text is a little larger in general. For example a 1.8 KB PNG icon file as a graphic, became a 2,498 byte (4 KB on disk) file when saved by TextMate. It will probably vary depending on the compression ratio if it is jpg as well as other factors. Once it is decoded in the container field in an image file format, it goes back to the original graphic file size.
Hi Doug
I actually don’t think this example is great for using Base64 functions. However, there are a lot of many other great uses. E.g. sync function or web service integrations, to name a few. And it is actually really solid. I did a test with encode and decode a 3,5 GB file and it worked fine. (though it took some time, of course…)
If you drop me an email, I have added another trick to accomplish, what you do in your demo, I would send it to you…
In my email conversation with Claus, he suggested some interesting alternate uses for this technique, including sending images to web services. I have added his variation of the Base64Encoding/Decoding technique which uses global variables to the demo file, as well as an example of a calculated field employing images.