Skip to content

Transferring and receiving data using QR codes

Both transferring and receiving functions are implemented within commands. There are two new keywords introduced to support this functionality; transfer and receive. Both keywords can be placed within the execute block of a command and they can return OK and CANCEL so the developer can perform additional actions based on their outcomes.

Transfer

command TransferDataCommand {  
   label = "Transfer Data";  
   icon = "upload";  
   enabled = [true];  

   variable CustomerNo;  

   execute {  
      set CustomerNo = "ACME";  

      transfer(CustomerNo, "ACME Industries") {  
         when OK {  
            alert("Data transfer ended.");  
            exit;  
         }  
         when CANCEL {  
            alert("Data transfer cancelled.");  
            exit;  
         }  
      }  
   }  
}  

The transfer function accepts a variable number of parameters and they can be variable identifiers, column identifiers and constant values. In the example above, we are passing in two parameters, the first one being a variable holding the value “ACME and the second one a constant string having the value “ACME Industries”. The QR code will be generated by extracting the values from these and then combining them.

Note: The maximum number of bytes that can be transferred using QR code is 2953 so it is advised to only send the required values.

When the transfer command returns, different logic can be executed based on whether it was successful (OK) or user canceled (CANCEL). In this example, we show an alert indicating the status.

Receive

command ReceiveDataCommand {  
   label = "Receive Data";  
   icon = "download";  
   enabled = [true];  

   variable VarA;  
   variable VarB;  

   execute {  
      receive(VarA, VarB) {  
         when OK {  
            alert("Customer No: ${VarA}, Customer Name: ${VarB}");  
            exit;  
         }  
         when CANCEL {  
            alert("Data receive cancelled.");  
            exit;  
         }  
      }  
   }  
}  

Like the transfer command, the receive command also accepts a variable number of parameters and it will return the results as OK and CANCEL. The parameters can only be variable identifiers or column names in this case. In the example above, we are receiving two values into variables VarA and VarB.

The receive command will trigger the device QR code scanner and read a value from a valid QR code. If an unsupported code was read or bad data was received, an error message will be shown to the user. It is important to note that you must pass the same number of parameters to the receive command as you did for the respective transfer command, or else the process will fail because there is a mismatch between the number of values sent and the number of values decoded from the QR code.

Testing the flow

Once the transfer and receive functionality is implemented, it needs to be tested to ensure that the flow works properly. When the transfer command is executed on the client (all three platforms), a dialog box will be shown with the QR code. The user can select one of two options, to accept or cancel the dialog.

  • If OK/Check mark was selected, the result block for OK will execute
  • If Cancel/X mark was selected, the result block for CANCEL will execute

When this dialog is being shown on a device, you can use another device to test the receive functionality. It will open the device camera (Android/iOS only) or you can scan the QR code using a connected barcode scanner accessory (Windows only). Once the QR code has been scanned successfully, an alert message will be shown requesting user confirmation to either continue or cancel.

  • If the user decides to proceed, the result block for OK will execute
  • If the user decides to cancel after the QR code has been successfully read, the result block for CANCEL will execute
  • If the user decides to dismiss the QR code scanner/navigate back at any point before a valid QR code was scanned, the result block for CANCEL will execute.

On Android and iOS, only the device camera can be used to scan a barcode. External barcode scanners connected via USB/Bluetooth are not supported on these platforms. If a Scandit license key is set for the respective platform, the device will use Scandit barcode scanner, and otherwise it will fall back to the default ZXing barcode scanner.

On Windows, scanning barcodes through the device camera (both front and back) is not supported. You will need to have a Windows UWP POS certified barcode scanner for full functionality, or otherwise any USB/Bluetooth connected barcode scanner which can read text into a text field would work with limited functionality.

  • If a fully compatible barcode scanner is detected, the dialog box will show a prompt to scan the QR code using the scanner at which point, the user can scan any barcode and the dialog will dismiss if a valid barcode was scanned.
  • In the case where a fully supported barcode scanner is detected, the user can still use legacy scanner devices. There will be a text field shown in the dialog, to which the user can set the cursor to, and then perform the scan using the device so that it will add the text to the input field. If valid text was received, the dialog box will dismiss, and the result will be shown to the user.

Please refer to https://docs.microsoft.com/en-us/windows/uwp/devices-sensors/pos-device-support for a list of Windows UWP POS supported peripherals.