[Last updated November 3, 2021]
A barcode is an optical machine-readable representation of data. A lot of things around us have barcodes. You will find them in virtually any packaged item you buy, in the back cover of books and most likely somewhere in the laptop, its power adapter, or the PC you may be using right now.
Typically, barcodes are attached to things using a sticker, or simply printed on them. You can put any data you want in a barcode, but generally they are used to unequivocally identify the item. Barcodes are designed to encode data in a way that can be quickly scanned using either a barcode scanner, or through the camera of your smartphone.
In the image, a barcode has been placed in the back of a road sign. The barcode uniquely identifies the asset, but also carries information about the installation date, manufacturer and other important information.
An inspector, using the Survey123 field app, can quickly scan the barcode and load all the asset information into the form. At that point, the form can be completed and submitted.
Types of barcodes
There are multiple flavors of barcodes They are organized into two categories: linear and 2D (matrix) barcodes.
The original barcodes where all linear. They were invented in the 1960's, popularized in the 1970's and still the most commonly used today. Here is a linear barcode representing the value 03600029145
Two-dimensional barcodes can encode more information. A popular one these days is the QR code, which you may have already used from your smartphone to quickly access a web site, or to download a mobile app.
There are lots of different types of barcodes, even for each of these two categories. Choosing one type or the other will depend on what type of data you want to encode (not all types support international characters for example), the size of the data, the amount of space you have for the sticker, etc
Another important aspect before choosing the barcode type to use is licensing. Many barcode styles are patented and you cannot use them to print your own data. You can learn more about the different types of barcodes in Wikipedia.
From a practical perspective, if you would like to create your own barcodes, a safe bet is to go with a 2D style, as it will give you good flexibility to store data of different sorts or one in the public domain, such as Aztec or QR Code.
There are different ways to print barcodes. To start playing around a bit, I personally liked qr-code-generator.com and also barcode-generator.org. You will also find API's, to create these barcodes programmatically, as well as solutions of all sorts to print stickers: in bulk, from a pocket printer, to print waterproof barcodes etc There is really a world around barcodes. If you are hardcore enough you will even find people who will tattoo them on you.
Barcodes in Survey123 (The Basics)
If you would like field users to be able to scan a barcode and get the data added to your survey, you need to add a barcode type of question. As shown in the screenshot below, the XLSForm specification includes a barcode question type.
Barcode questions, by default, are shown in your form as an input box with a barcode scanner button o the side. Users can either manually enter text or tap the scanner button to trigger the device camera. By simply focusing on the barcode the barcode will be scanned and the data from it added to the form.
Survey123 supports the following barcode types: QR Code, Code 39, Code 93, Code 128, EAN 8, EAN 13, UPC A, UPC E, UPC EAN Extension, Aztec, Codabar, Data Matrix, ITF, MaxiCode, PDF 417, RSS14 and RSS Expanded.
By default, the Survey123 field app will automatically scan all barcode types except Code-39 and PDF417. If you need to scan Code-39 or PDF417, go into the scanner dialog settings and activate the format you are targeting. Your barcode preference will be remembered.
To help you get started, Survey123 Connect includes a Barcodes survey design sample. Open Survey123 Connect, click on New Survey, and then look in the Samples category. Publish the survey and download it into your device to familiarize yourself with the XLSForm syntax and the app experience.
Minimal appearance and calculations
Barcode questions in Survey123 support the minimal appearance. When used, the question will not show any type of input text box. Instead, all the user will see will be the name of the question, as well as the button to start the scanner.
The minimal appearance in a barcode question is typically used in combination with calculations in other questions: the barcode question is used to fetch data, and the calculations extract that data and display it to the user.
Say for example you want to use a barcode to store the Unique Identifier of an asset and the company that produced it. Just like in the barcode on the side.
We would not want to show all that information in a single field, because it would be confusing to the field user, and somewhat useless stored that way.
Using the minimal appearance and calculations you can parse the information from the barcode and present it and store it in different fields... like in the following example:
If the information in the barcode is more complex, you can use a custom JavaScript function to parse its contents.