2D Bar Codes are all the rage these days. These new style bar codes can store considerably more data than a standard bar code. Combined with the wide spread availability of iPhones and other smart phones with a built-in camera, capable of scanning these codes, there is an opportunity to employ these codes for a variety of purposes.
An example of this was done recently by my son, Cory Alder and his company Davander Mobile Corporation. He built a solution for a fair trade coffee company called Ethical Bean which involves a custom iPhone app talking to a FileMaker back-end system that keeps track of these bar codes. The company prints a 2D bar code on every package of coffee it sells. Customers can scan the bags, either in the aisles of the supermarket, or when they get home with their iPhone. The 2D bar code contains a unique URL for each batch of coffee. The app then will retrieve all kinds of useful and interesting information about the source of the beans that are blended in, the ratio of how they were combined, where the coffee came from, right down to maps and videos of the farmers responsible for the beans. It is a pretty cool marketing concept and really uses the technology well to open up information about what ‘fair trade’ actually means. If you are in the market area for Ethical Bean (Canada), it is worth checking this out. Even if you don’t have a smart phone, you can type the bar code number into a browser and see the information displayed.
This project and the recent release of a Custom Function for doing 2D bar code generation got me thinking about how to create and store these codes in FileMaker. I had been looking for an excuse to implement the free and awesome 360 Works ScriptMaker plugin as well. I created a little demo file of this in action.
Demo of ‘Create and Store 2D Bar Codes’ in FileMaker
1) Enter a Dimension for the Bar Code size
2) Enter some data here. This could be address information or a longer URL.
3) This is a web viewer driven by the Google Chart API. It is generated on a Google server.
4) Click this button to run the script that grabs the bar code directly from the Google server. It stores a copy of this image in a container field
5) The Container field to store a 2D bar code from Google.
In testing it seems that the 2D Bar Codes generated by Google’s 2D Generator have a maximum capacity. This appears to be a limitation of the Google Charting API and not inherent in the 2D Bar Code format.
Maximum Dimension: 500
Maximum Characters: 1930
There seems to be an inverse relationship between the dimensions and the amount of data the bar code can store. If the dimension is too small and the data information is too large, it won’t display. There is also a question as to whether a bar code scanner could read a 2D bar code that small. Correspondingly, if the data is too large and the dimensions too large, Google maxes out what it can return.
Plug in some numbers and experiment.
Create a Custom Function
Here are the steps I used to build this demo file. First I added the Custom Function.
The Custom Function
Creating the Custom Function for ‘Google2DBarcode’
All this Custom Function does is build a calculated URL to send to the Google Chart API app engine. This could be done simply by pasting the appropriate fields into the right places in the URL. This Custom Function makes it a little easier, but is not totally necessary.
The basic format of the URL is : http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250×100&chl=Hello|World
Google2DBarcode Custom Function
// Function: Google2DBarcode
// Variables: Width, Height, Data
// It looks to me like Width and Height are not really needed as the bar code always comes out square and in fact a single dimension variable would work just as well. The reason they are in the URL string this way is to facilitate other types of graphs.
Trim ( Substitute (Data ; " " ; "+" ) ) &"&chld=L|1&choe=UTF-8"
//Author:Bill K, BRC http://private.com
There is an ‘On Open’ script to call the ScriptMaster function and a ‘Grab a BarCode’ script. Set this ‘On Open’ script to run in the File Options.
The ‘On Open’ script calls the ScriptMaster function
This step makes it available to the database, provided you have the ScriptMaster plugin installed.
The script ‘Grab a BarCode and put it in a Container field’
Set the Image container field with the GetURLasContainer External Function.
Use the ‘GetURLasContainer’ external function in a script
Use this calculation to call the Custom Function ‘Google2DBarcode’ and set the Container field with this content.