Generation of QR codes

There are several ways of generating a bar code in FileMaker, the main ones being, a formatted field with a barcode font or using a plugin. The difference being that plugins give more control over the attributes and return a graphic.

If you want to generate a QR code there is no font option but we can use google.

With the help of a custom function from Matthew Greger (matthewg@thebusinesshelper.com) called QR_Code_Container and 360 Works Scriptmaster  (http://www.360works.com/scriptmaster/) we can call the google code api and return into a container field a graphic of our QR code.

Matthews function allows you to pass the data to be encoded along with the height and width of the QR code and control of the encoding, error correction and margin size.

So we now know how to create a QR code but what use can we put them to.

You could simply just use a key field for the ability to quickly find an item i.e. checking stock in a warehouse, but we could use a normal barcode for this.

The whole reason for using QR codes is that the amount of data we can encode is vastly increased. So we could encode a URL that takes a customer to our website. If the code is added to our stock labels the URL could then take the user to the correct page of our site that display information about the product. You could even put the import information in the QR code itself.

There is one down side to all this text information is that it is just text, how this information is shown to the user is down to the device and the software used to scan.

So what could be used that would be useful…

How about a vCard with all our information and we can also include our website url as part of a vCard.

To build our vCard we just need the correct structure which is basically

BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest;Mr.
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=WORK,VOICE:(111) 555-1212
TEL;TYPE=HOME,VOICE:(404) 555-1212
ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of America
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America
EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com
END:VCARD

Not all the tags are needed and you can get away with just Name and Address if you want.

So is there anything else you need to know if you are generating this from FileMaker?

Yes.

The lines in a vCard are separated by a line feed and not a carriage return which is the usual way of breaking lines in FileMaker.

The way round this is to use the char() function and the value for a line feed is 10 so our FileMaker calculation for this example would be

“BEGIN:VCARD” & char(10) & “VERSION:3.0” & char(10) & “N:Gump;Forrest;Mr.” & char(10) & “FN:Forrest Gump” & char(10) & “ORG:Bubba Gump Shrimp Co.” & char(10) & “TITLE:Shrimp Man” & char(10) & “PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif” & char(10) & “TEL;TYPE=WORK,VOICE:(111) 555-1212” & char(10) & “TEL;TYPE=HOME,VOICE:(404) 555-1212” & char(10) & “ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America” & char(10) & “LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of America” & char(10) & “ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America” & char(10) & “LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America” & char(10) & “EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com” & char(10) & “END:VCARD”

When this code is now scanned a new contact will be created by the user and they can now contact us in the way that they prefer.

Simon Ward

Simon has been developing FileMaker databases since the late 90s and joined Linear Blue in 2006. Over this time he has developed database systems for clients in many different industries from Order Processing to Book Publishing. Simon’s BSc in Chemistry from Thames Valley University comes to the fore in his analytical skills and he is certified in FileMaker versions 7 through 12.

More Posts - Website

3 thoughts on “Generation of QR codes”

    1. Rob
      Yes Matthew Greger’s custom function is set to use the google API which is set to expire on 20th April 2015.
      However there are other people who offer an API to create QR code. I have chosen QR Server (http://qrserver.com/api/documentation/create-qr-code/) as they state in their documentation that their service is free for business use.

      I have updated the custom function to use the new URL and accept the same parameters so scripts and calculations still work.

      New code:

      // Name : QR_Code_Container ( Data, Width; Height; Encoding; ErrorCorrection; Margin )
      // Creator : Matthew Greger (matthewg@thebusinesshelper.com)
      // Date : 4/1/2011
      // Update : 6/1/2014 change API to QRServer
      // By : Simon Ward (simon.ward@linearblue.com)
      // Purpose : Generates a QR Code into a container field using QRServer’s API & 360Works ScriptMaster
      // : Must Load the ScriptMaster function GetURLAsContainerpart2( url ), now done in this CF
      // : http://qrserver.com/api/documentation/create-qr-code/
      // : http://www.360works.com/scriptmaster/
      // Params : Data – valid URL or any text you want displayed in a QR Code
      // Params : Width – width of code in pixels
      // Params : Height – height of code in pixels
      // Params : Encoding – empty is default and is UTF-8, other options, ISO-8859-1
      // Params : ErrorCorrection – this is the level of error correcting, default is L, (L, M, Q, H)
      // Params : Margin – white space around the QR Code, default is 4 rows, these are not pixels

      //

      Let ( [
      //Register Plug-in Function
      $plugin = RegisterGroovy( “GetURLAsContainerpart2( url )” ; “new URL(url);”; “isGui=false” );
      // QRServer API
      $url = “http://api.qrserver.com/v1/create-qr-code/?”;
      // Data must be URL Encoded
      $data = “data=” & GetAsURLEncoded ( Data );
      // Dimension
      $dim = “&size=” & Width & “x” & Height;

      $encoding = If (IsEmpty ( Encoding ); “”; “&charset-source=” & Encoding);
      $error = If (IsEmpty ( ErrorCorrection ); “”; “&ecc=” & ErrorCorrection);
      $margin = Case (IsEmpty ( Margin ) or margin < 0 or margin > 50 ; “”; “&margin=” & Margin)
      ];

      Case (

      //Trap for error registering plug-in Function
      $plugin = “Error”; “ERROR¶Problem Registering¶Function”;
      //Trap for missing plug-in
      $plugin = “?”; “ERROR¶Missing ScriptMaster¶Plug-in”;
      //generate QR code
      GetURLAsContainerpart2( $url & $data & $dim & $encoding & $error & $margin )

      )

      )

  1. cool! thanks for updating that. That’s the same QR generator I have been using for a much simplified version of a qr code creation script. It doesn’t use a plug-in (which means it works on iPads/iPhones with both FileMaker 12 and 13):

    set variable [$formula; “http://api.qrserver.com/v1/create-qr-code/?data=_placeholder_&size=120×120”]
    insert from URL [ Select; No dialog; myTable::container; substitute ( $formula ; “_placeholder_” ; barcodeDataField ]

    Normally, the formula would be stored in a preference table where the users can easily tweak it, but it works nicely in many situations.

    Rob

Leave a Reply