(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.data-privacy-src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-PF5R8F7');

Knowledge Base

Custom On-Device Validation

What Is Custom On-Device Validation?

With our ‘Custom On-Device Validation’ (COV) feature, you can write your own JavaScript to validate based on the scanned barcode, the response text, and the app user’s answers to in-app prompts. The service type must be a Record On-Device or Validate On-Device with manual upload to our server or auto-sync to our server (or yours). Learn more about auto-sync here.

You will find this COV option on the Advanced Step when creating or editing a service. Look for “Enable on-device custom validation” under Miscellaneous. Copy and paste your script or one of the scripts in the examples below.

Here are general Custom Offline Validation guidelines for developers. This PDF includes instructions for setting up the Custom Offline Validation script for the answer validation described.

Examples of What COV Can Do

  • The decryption of encrypted barcode data, where app users can see the decrypted result in the response and the result optionally becomes part of the scan record.
  • Validating primary scans against the barcode values in an associated database is a standard feature.  With COV, you can also validate primary scans based on predefined conditions and primary scans against question-answer barcodes for an exact match or substring match in the database’s response text. The question-answer can be from a barcode scan or from other question options, including manual entry, drop-down menus, etc. See the “A/B/C Barcode Matching” COV section below.
  • Convert HEX scan values to ASCII values. On the Advanced step when creating your services check the “Enable on-device custom validation” box and then paste the script from this PDF.
  • Validate answers to questions using Regex. Answer submission is blocked if it doesn’t meet the criteria set in your Regex. You need to enter the QUESTION_ID,  the Regex PATTERN, and optionally the ERROR MESSAGE to show to the app user. This PDF includes the instructions for setting up Custom Offline Validation.

Here are a few detailed examples with sample scripts:

Conditionally Capture Primary Scans

Option 1: Scanning one barcode at a time

Here’s a PDF of the filtering script to use regex to define what scan values can be captured. If the scanned value doesn’t match the regex pattern, the app user will see an error message and the scan will not be recorded.

Editing the script:
var errMsg: This is the message given to the app user when the scanned value does not match the regex pattern.
new RegExp(“REGEX_PATTERN_HERE”): You can enter several regex patterns using this format. You must escape special characters, e.g. from [\s\S] to [\\s\\S].

Option 2: Batch scanning up to 200 barcodes in a single camera view

Here’s a PDF of the filtering script to use regular expressions (“regex”) to define what scan values can be captured. If the scanned values don’t match the regex pattern, the app will automatically remove non-conforming values from the record.

Editing the script:
var errMsg: This is the message given to the app user when the scanned value does not match the regex pattern.
new RegExp(“REGEX_PATTERN_HERE”): You can enter several regex patterns using this format. You must escape special characters, e.g. from [\s\S] to [\\s\\S].

A/B/C Barcode Matching

The A/B/C Barcode Matching COV alerts the app user when two or three barcodes scanned sequentially match or don’t match.

  • The primary scan (“Tap to Scan”) is matched to a standard question-answer or session question-answer.
  • The primary scan is matched to the response text in an associated database.
  • A standard question-answer or session question-answer is matched to the response text in an associated database.
  • A standard question-answer or session question-answer is matched to another standard question-answer or session question-answer.

Note: The response text match can be an exact match or a substring match. To enable this, please review our instructions about matching barcodes. Matching can be done with barcode scans or text entries.

Change the Scan Response with Substring Matching to Scan Values or Response Text

This PDF with instructions checks your scans for a given string using RegEx. When the string matches all or part of the scanned value, the script will check your defined array for the response to give. In the example, the response gives a bin number and color for sorting assets based on their barcode value. Additionally, it gives invalid responses for any scan that does not match the other string options. The script can be used with record-only or validate scan services provided the service is an on-device service type. The service will work normally outside of your defined strings. Scans not in the database of a validate-scans service type are invalid; scans that do not match the defined string of the array using a record-scans service are recorded as valid with no response. This PDF shows a scan response HTML example.

The same script can be used when matching the response text except you need to change the code line that says “matchFound(data.scanValue)” from “data.scanValue” to “data.scanResponse”.

Note: Be sure to escape the pattern as shown in the examples. To use HTML in the response, escape the string in the COV script.

Conditional Override of Scan Validity

Validation statuses can be over-written when certain criteria are met. For example, a normally valid scan can change to an invalid scan or a normally invalid scan to a valid scan based on:

    • the answer an app-user submits to a prompt (a “Question”);
    • when it detects certain text within the scanned value;
    • when it detects certain structured text within the standard response for the scanned value.

Here is an example using a yes or no question. Note that the error message at the bottom can be changed as well.

Here is an example returning a valid response even if a check-digit is not in the scanned value but is in the associated database. To clarify, that means if the database includes the value 11111111111C and the scanned value is either 11111111111C or 11111111111, both will return a valid response.

Custom Validation Override by App User

With this script, the scanning process can be temporarily halted so an app user can optionally override the validity status under certain conditions. For example, in the ticketing world, if a ticket must be used before a certain time, normally the result would simply be invalid. However, using this script, the app user will be alerted that the time has passed, and if the patron is willing to pay an additional fee, the app user can override the invalid status upon payment.

Also with this script, an app user can be alerted when a scanned ticket or ID needs additional checking. For example, also from the ticketing world, if a worker can enter for free, the app user can be altered to check their worker ID before admission.

Setting up override functionality is mostly copy and paste but you may want to edit the script based on your intended use. Ask support@codereadr.com for help if needed.

Combining Consecutively Scanned Values

Primary and secondary scans (i.e. question-answer scans) can be combined to simply create a scan record or to optionally be validated against an associated database. So, for example, a primary scanned value of “123456789” and a secondary scanned value of “abcdefghij” can result in a fully combined value of “123456789abcdefghij” or a partially combined value of “567abc“.

In this PDF you will see a sample script for combining up to three scanned values using regular expressions for defining what top capture and combine.

Verify the Accuracy of Cycle Counts and Inventory Audits

How does instant count verification work? The counter is assigned credentials by the CodeREADr account administrator. They download the CodeREADr app from Apple’s App Store or from Google Play and then sign in with their issued credentials. Once signed in, the app will automatically download the administrator-supplied inventory database including the system’s current counts.

The counter scans an item’s barcode and then enters the counted quantity. The app will compare the manually entered quantity with the actual system quantity stored on the device. If it matches, the app will indicate a valid scan. If not, the app will indicate an invalid scan. If the quantity is off, the counter can then recount that item.

Please refer to this PDF to help you configure instant count verification.

Verifying Question Answers

Option 1. Validate the combination of the primary scan value and a question-answer scan value or manual entry against a database. PDF Instructions

Option 2. Validate a secondary scan value or manually entered value against a database. PDF Instructions

Detailed Flow

  1. App user scans from the mobile app’s  “Tap to Scan” screen to validate a “primary” barcode value that’s in an on-device database, i.e. column 1 of the database import (UPC, SKU, Serial Number, ID, etc).  If the scanned value is in the database, the app user will see a green valid screen and then be presented with a question prompt. If the value isn’t in the database, the app user will see a red invalid screen and not be presented with the question prompt. 
  1. The question prompt answer can be answered manually or they can scan a barcode. For option 1, the COV script will check if the combined primary-answer value is in column 1 of the database. For option 2, the COV script will check if the answer value is in column 1 of the database. In both cases, if the value is in column 1, then the scan can be successfully submitted. If it is not, the app user will see an error message and be returned to answer the question again.

Kitting: Validate Items and Quantities in a Kit

With this COV script, a database includes the items in the kit, the quantity of each item, the number of kits to assemble, and the kit ID.

Follow this guide for instructions to Kitting Verification App Setup. It includes a script to be pasted into the “Enable on-device custom validation” field on the Advanced step when creating a Validate Scans service type.

After uploading a database of kits, your users can enter the work order number and see a list of kits they need to complete for that order. Importantly, a user can complete many kits at a time rather than finishing each one individually. This is referred to as a batch.

For example, let’s say we have 25 kits in our work order and each kit contains an apple, an orange, and a banana. If our batch quantity is 1, the user will need to scan an apple, an orange, and a banana to complete the batch. If our batch quantity is 5, the user can scan 5 apples, 5 oranges, and 5 bananas in any order. Once all the fruits have been scanned for these 5 kits, the batch is complete.

This PDF document includes HTML code to show the status and messages to the app use. Paste the HTML into the Advanced step’s “Alter Response” replacement field. The pattern for this replacement is:

^([\s\S]*?)$

We recommend disabling the response label under the “Enable custom display configuration” option using this text:

{"response_label":""}

Note: This COV kitting script is a sophisticated, kit verification tool. However, if you have a limited number of kits to verify, you could instead deploy a service with an associated database of items for each kit. The app user would select the appropriate kit to start processing. A kit could include multiples of the same item using either conditional validation overrides (no-coding) or a simple COV override (simple coding). Also, duplicate checking could be enabled with a reset. If you need help, please contact us at support@codereadr.com

Loading and Unloading

You can prevent duplicates of certain assets as they are loaded onto a truck, warehouse, dock, etc. Follow these instructions for loading assets for delivery to dealers. In the script, asset IDs are scanned and added to a database along with a secondary scan. Here, the second scan is a driver ID. The driver ID is added as the response text for the asset ID in the database. [Note: This script is for online services and requires the “Custom Validation Middleware” feature. Email support to get access.]

Simultaneously, duplicate checking is turned on for specified asset prefixes. Finally, this script allows for duplicate checking reset based on the device time specified.

For unloading, the database containing the asset IDs and corresponding driver IDs can be used for a service to check that the scanned asset ID is in the database. Additionally, using A/B compare, you can check that the dealer ID for that value matches the dealer ID in the database.

Please contact support@codereadr.com with your specific requirement. For some applications, we will quote writing the script for you.