Scanning Barcodes

Scanning Barcodes

Barcode scanning capabilities are integrated into our Profound UI Mobile Client; this is possible through the use of a Cordova barcode scanning plugin linked here.

If you are creating your own Apache Cordova app and are installing the plugins, please use the following links corresponding to the version of Cordova you are using:

  • v5.0.0+ - Note: you will need to install this version from the repository as the suggested add code will install the latest version.

  • v7.1.0+

Calling the plugin in an application running through our Mobile Client is a matter of using some javascript coding. The following is a simple example of a barcode application that should give a proper idea of how to create a Rich Display application that uses barcode scanning.

This application consists of one Output field bound to the variable "code", a Textbox bound to the same field, a "scan" button that will trigger the barcode scanning on a mobile device, a "save" button that will submit the barcode read back to the RPG code, and an exit button that closes the application. The following screenshots show the values for the scan button, as well as the javascript code needed for the onclick event of the button.


What the code is doing is defining a success and failure function that will be passed along to the scan function of the scanner object. These functions will fire depending on whether your barcode reader is successful in scanning a given barcode or not. Inside of these functions, we define the behavior we wish to occur depending on the context. For both of these functions, a parameter will be passed that gives the relevant info needed; in a success function, the object that is passed contains a "text" property that contains the value of the barcode scanner and a "format" property that contains the format type of the barcode scanned. In a failure function, the object passed is just a string containing the reason for the failure. You can see in the success function we are changing the value of the "code" textbox to be equal to the "text" property of the passed object called "result"; this changes the textbox's value to the scanned barcode's value. The if statement surrounding the scanner variable and scan call is checking to see if you are on mobile running Apache Cordova (which our client uses) first. If not it will automatically call the failure function (in this example nothing is passed into it, but you could pass it a string explaining that you are not on a mobile device), which simply throws an alert that displays the error.

Here is the code driving this screen:

The exit button is bound to the btnExit indicator, which ends the program. The save button has a "" call in it's "onclick" property which submits the screen to the code.