This is part 2 in a 3-part series.
In Part 1 of this 3-part post examining bar codes, magnetic strip readers, and FileMaker Go, we looked at the tools necessary to integrate all the components into one FileMaker Go solution. We will focus on just the bar code and FileMaker portion here. The necessary resources are listed in part 1, and the card reader portion will appear in part 3.
To create the FileMaker Go app, we create the database up in FileMaker, and then place the app on the iPhone or iPad (via iTunes or web page, for example). Since the device is mobile and connection to a networked file can get iffy, there are advantages to having all the action local on the device, at least initially. Later, you can sync the data with the server though a variety of methods (GoZync, MirrorSync, etc). We created a simple test database (see demo file below). This file contains both the scanning and bar code reading capabilities.
The Interface
The database front end is fairly simple, and consists of a field that stores the data, plus three buttons. The Scan button handles a single scan, and could be set up for either pic2shop or CNS Barcode. The Swipe button opens the CardSwipe reader app, while the Multi-Scan button works only with CNS Barcode.
Pic2Shop
The first app, Pic2Shop, scans a single barcode, or EAN number. (EANs are 13-digit barcodes, but pic2shop will still scan older ISBN10 numbers). A good starting point is to create a button that launches the script, such as “Scan”. This script in turn launches a script to open the barcode app. In the sample database we have both the pic2shop and CNS Barcode available, and you can comment out one or the other while testing each method. We have a parameter in place to handle the two different buttons, the individual
Scan”, and the “Scan Multiple”. The “Open barcode app” scrip contains the key line, which is the “Open URL” script step. Inside this step you build the URL scheme to send to the iOS app – pic2shop or CSN barcode. The callback requirements must have the EAN string in the url, and for FileMaker 12 this looks something like
pic2shop://scan?callback=fmp://$/GoInput?script=Scan¶m=EAN
This url breaks down as follows:
- the app: pic2shop://scan?callback=
- the callback app, in this case Filemaker: “fmp://” for FileMaker Pro 12
- the location of the FileMaker app: $ for an application already open on the phone (~ to open a database on the device, and hostname if hosted remotely)
- the file name: GoInput
- the script: Scan
- the parameter: EAN (the barcode read by the app)
The url needs to be encoded to handle certain characters, and so the URL would change to this:
pic2shop://scan?callback=fmp%3A//%24/"&Get(FileName)&"%3Fscript%3DScan%26param%3DEAN
Characters | Encoded |
---|---|
Dollar $ | %24 |
Space | %20 |
Equals = | %3D |
Ampersand & | %26 |
Colon : | %3A |
Question Mark ? | %3F |
The last piece, the “Scan” script, handles the data received from the device. Since the barcode resides in the parameter, your script simply needs to insert the data into a field. Before looking at this script, we’ll switch over to see how CNS Barcode behaves.
CNS Barcode
The only variation we used was to enable the multiple scanning option on CNS Barcode, and this was set up via the script parameter and a Case statement inside the URL. If you are scanning multiple barcodes, having to click the scan button each time can slow down the process. However, one caveat is that CNS Barcode in this mode appears very sensitive and will scan very quickly and often the same barcode multiple times, and in some cases scanning a portion of the barcode that you don’t want. Instead of the full EAN 13 you might end up with a five digit number. When scanning multiple barcodes, all the barcodes appear in one return-delimited list in the clipboard. This list then is pasted via the script into one field in FileMaker. To split out the items, you could either extract the unique values in the script or using a custom function, and then loop through the unique values to create your records in FileMaker. The CNS Barcode Open URL script step then looks like this:
"cnsbarcode://scan?" & Case ( $param = "multiple" ; "scanmultiple=yes&" ) & "launchurl=" & GetAsURLEncoded ( "fmp://$/" & Get ( FileName ) & "?script=scan¶m=::barcode::" )
A simple Case statement checks whether we chose a single or multiple scan. Next, add the launchurl to the FileMaker database (the name of the file), and the ::bardode:: parameter (just like EAN for pic2shop). The Open URL calculation is broken down into respective parts, but really is one continuous URL.
The Scan script itself places the barcode into a text field. With multiple data you would loop through and create multiple records.
Set Error Capture [ On ] Go to Layout [ “Input from Barcode” (zSystem) ] If [ Get( TotalRecordCount ) = 0 ] New Record/Request End If Set Variable [ $code; Value:Get(ScriptParameter) ] If [ not IsEmpty($code) ] # If [ PatternCount ( $code ; "Multiple" ) ] Paste [ zSystem::gScanData ] Else [ Select; No style ] Set Field [ zSystem::gScanData; $code ] End If Commit Records/Requests # End If # Go to Layout [ original layout ] Set Variable [ $Barcode; Value:zSystem::gScanData ] Loop Exit Loop If [ Let ( $i = $i + 1 ; $i > ValueCount( $Barcode) ) ] New Record/Request Set Field [ ScanInfo::inputText; GetValue( $Barcode ; $i ) ] Commit Records/Requests End Loop #
This script creates a new record for each scanned item. In theory once you have a valid barcode you can reach out to other databases and get additional information if required, or a custom barcode would be written to contain all the information that you need.
Note the number in the red circle at the bottom. When scanning multiple items you can see how many are currently in memory. You can view the details by clicking on this icon.
Note the first item in the list, which contains ALL the numbers from the barcode, including the smaller barcode section, whereas the others are all ISBN numbers. In your database if you are scanning books, you would need to validate the numbers before trying to pull additional information.
Finally, when you click done, the app switches back to FileMaker via the callback section in the Open URL script step.
CNS Barcode’s multi-scanning action seems to quickly scan the same number multiple times, and also sometimes scans barcode numbers other than the ISBN10 or 13. Possibly there are some settings that might limit such behavior. Otherwise the multi-scan mode significantly speeds up getting that barcode data into FileMaker without switching back and forth between the apps.
The sample file: GoInput.fmp12 applies also to the magnetic strip reading process in part 3.