Scanning Barcodes and More With FileMaker Go – Part 2

In Part 1 of this 3-part serices 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 barcode 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 for example). Since the device is mobile and the 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 barcode 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.

Screen shot of scan/swipe in FileMaker Go

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” script 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
CharactersEncoded
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

iPhone Screen Shots

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.

Scanning a barcode

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.

Details for scanned items in multi-scan mode with CNS Barcode

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.

Viewing details for a scanned item

Finally, when you click done, the app switches back to FileMaker via the callback section in the Open URL script step.

New record in FileMaker Go with data from the barcode

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.

GoInput.fmp12

About Anders Monsen

Anders Monsen is the Architect of Integration for MightyData. Anders is a certified FileMaker Developer 9-12, Authorized Trainer 9-12 and FileMaker Developer Conference speaker. He's a runner and triathlete, and spends his other free time driving his two kids to various practices and games.
This entry was posted in Barcodes and tagged , , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

36 Responses to Scanning Barcodes and More With FileMaker Go – Part 2

  1. Mauricio says:

    Hello. I am new to FMP Go and I’m trying to follow your indications to use either pic2shop or CNS to read barcodes from my iPad but I am lost. Could you send me the actual script as it has to be written, please? Thanks

  2. Hi Mauricio, did you take a look at the sample file? The scripts that I refer to in the article are in this open file.

    Regards,
    Anders

    • Mauricio says:

      Hi. Thank you for taking the time to answer. When I first read the articles I did it in a rush and missed the sample file. I did see the file after coming back to reread the article. I beg your pardon. And thank you again

  3. Michael says:

    Hi Anders,

    Thanks for your post. It is interesting and helpful. I’m developing a native iOS app in Objective-C. I wonder whether I can retrieve the records of Filemaker Go in my app with URL protocol.

    Thank,

    Michael

  4. Andrei Iancu says:

    Hi Anders,

    Not sure if I’m doing anything wrong or if this is a bug from pic2shop.
    I downloaded your sample file and stripped it down a bit to use only pic2shop, as well as use the data passed by pic2shop to do Finds or entering data. However, while everything works great with regular barcodes, when I scan QR codes, all I get back is “EAN” instead of the text itself.

    Any tips on how to fix this?

    • Hi Andrei,

      Theoretically this should be possible, but I’m not sure if the free version allows this. The product description for the Pro version mentions the ability to add optional formats, including QR codes: “…scan?formats=QR&callback…” (see http://www.pic2shop.com/pro_version.html ). However, when I try this with the free version, either it doesn’t work, or there’s something else going on.

      Thanks,
      Anders

      • Paul says:

        Hi there,

        I’m currently working on a project for a Scout Jamboree in the UK. Trying to get pic2shop to bring back a QR code into FileMaker without much luck. Would be very grateful for any assistance, or feedback from our investigations.

        With Regards

        Paul

        • Paul and Andrei,

          I’ve tried several variations for QR codes, and have communicated with the support group at pic2shop. They state it should work, by simply adding the QR string to the callback. However, so far I’ve also been unable to get this to work, though EAN works seamlessly.

          Anders

          • Isaac says:

            Thanks Anders for your blog. I emailed pic2shop and they said to change EAN to QR. It works for me, but I can’t figure out the right combination to get both on the same line.

          • Isaac, that interesting. I tried using QR instead of EAN and nothing happened. I am able to get CNS Barcode to work for both EAN and QR codes, but no combination with pic2shop appeared to work for QR codes.
            Anders

          • Paul says:

            Would be very grateful if Isaac could share his actual line of code he has managed to get pic2shop to work with QR’s in FM. If that’s possible??

            With Regards

            Paul

            • Isaac says:

              Paul, the following is the command for QR I use.

              “pic2shop://scan?callback=fmp%3A//%24/” & Get ( FileName ) & “%3Fscript%3DFINDBarCodeScanAdd%26param%3DQR”

              I followed the info on this website and http://www.skeletonkey.com/blog/filemaker_go_barcode_scanning_with_pic2shop
              for development.

            • In my case the moment I add “QR” as the param instead of EAN, or even in addition to EAN, the script breaks. There is no callback to the script in the URL. The QR codes is scanned and then it jumps back to FileMaker, but fails to call the script. I have tried several variations, urlencoding manually or with the FMP calculation. In each case this breaks my script: param%3DQR. However, param%3DEAN works seamlessly.

              Anders

            • Isaac says:

              Hi Anders, my call back script is named FINDBarCodeScanAdd.

              Try replacing that with your script name in the url.

          • Paul says:

            Thank you for info, this unfortunately is exactly what my url looks like, but alas doesn’t work. Even replacing my string with the one you kindly supplied and changing the script name accordingly hasn’t resolved the problem. Back to the drawing board.

            • Isaac says:

              Strange. Ok, so I went back and tested again. I’m using FMS Advance 12, to host the file. Are you using FM Server to host the database?

              I ran into some trouble getting the same test database to work if stored the file directly onto the iPhone. Seems I had several copies of the database in FMGo12 under “Files on Device”. Once I removed them all and pulled it back in from email it worked fine. Maybe that is you issue?

          • Paul says:

            I’m hosting my solution on FM Server, I haven’t tried hosted via FM advanced. Will try that and see what happens. Will be a real pain if it’s caused by being hosted on FM Server.

            • Isaac says:

              Sorry I abbreviated. FMS Advance is FileMaker Server Advance. Not FileMaker Advance. If you want, I can upload my test file, but I don’t see an upload button here.

          • I am hosting my file locally on the device. I can try it on a server and see if that makes a difference. Ideally this should work on a file local to the device, since the person scanning may not have internet access all the time.

          • Changing the script name made no difference in my case. When I have QR in the string the scrip in the url fails to activate. I am checking into the server option.

  5. Ryan Lee says:

    Hi Anders,
    I tested your code on my iPad and it works great. Then I purchased the CNS Barcode and copied your code to my solution. The only thing I changed is the scan script to set one of field with the scriptparameter. However my solution did not work somehow: ipad stop at CNS Barcode and did not jump back to Filemaker solution. Could you tell what I did wrong? Thank you very much.

    R

    • Ryan Lee says:

      I just found out that the password may cause the problem. When I leave the account’s password as blanc, it did return to the Filemaker solution. But I need to use the password for different users. In this case, how to modify the “Open barcode app” script? Thank you very much.

      R

      • Ryan, not sure why you need a password or login for this script. Is this just to identify the user? Can you not use something like Get( PersistentID ) from within FMP for this?

        Anders

  6. I was having trouble with the pic2shop code handling file names with spaces in them. GetAsURLEncoded didn’t work, but the old notation of using ‘+’ instead of spaces did:

    Substitute ( Get ( FileName ) ; " " ; "+" )

  7. kkishnani@me.com says:

    my filemaker file is on the FMS 12 and is password protected, how can i add the account name and password in the url itself so that i don’t have to type account name and password when the app switches back to filemaker?

    • Isaac says:

      I also have my Filemaker file password protected. It does not ask me for a account name and password when I switch back. Does your account use the fmreauthenticate extended privilege?

  8. Paul says:

    It would appear the scanning and call back function is stingily affected by solutions that have any form of security placed on them.

    I have placed this functionality in several solutions that are ‘open’ with no issues. As soon as I place this in solutions that have different types of accounts it will not perform the call back script.

    I’ve tried having the scripts set with ‘run with full etc’ and this makes no different.

    Would love to know if some one could shed some light.

    With Regards

    Paul

  9. By open, do you mean the default admin account with no password? Or, does open mean running the process from one file calling another that’s not open? Since the database is open when you call the iOS app, it should find that open file and run the callback script.

    Anders

  10. Dilip Warkad says:

    Is there any type of Handheld device available where we can scan two barcodes simultaneously. Is this possible ? Please provide details

    Regards,

  11. Jim Meyer says:

    How do return the scanned data back to FMP? I click on scan and pic2scan opens and I can scan a barcode but I can not figure how to exit pic2scan and return to FMP.

    • Jim, the “scan button” script should do two things. It uses the script step “Open URL” which uses what’s allied a URL protocol to open pic2shop. In the URL there is an action—scan—with a callback to FileMaker using the FMP url protocol. This callback should have the file name and the name of the FileMaker script. In my example this script is called “Scan.” The script takes a parameter: EAN; the barcode being scanned.

      If your scan does not return you to FileMaker it’s possible the character encoding is not opening the file because there is an issue with the path in the callback. Make sure you don’t have spaces or colons, but use something like
      pic2shop://scan?callback=fmp%3A//%24/” & Get( FileName ) & “%3Fscript%3DScan%26param%3DEAN”


      Anders

  12. Milan says:

    Hi,
    very nice article, thank you, i decided to give it a go.
    I noticed that the downloaded file is opening somewhat slow on the PC, is there a particular reason for this, as it is a very small file with no data in?

  13. Isabella says:

    I have an iPad 2, OS6, I believe. I copied your GoInput database sample, disable the CNS barcode script step since I would have to purchase the app and I am just testing now. Nothing happens when I click/press on the SCAN button. Do I have to download a pic2shop app to be able to run the script?

    • Kirk Bowman says:

      Isabella – If you have FileMaker Go 13, use the Insert From Device script step to scan a barcode directly from the app. See this article for more information.

      If you have FileMaker Go 12 or earlier, you will need either pic2shop or CNS Barcode to scan a barcode. Also, the poor camera quality on the iPad2 makes it more difficult to scan a barcode.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>