barcodes for drivers licenses?

1225
5
Jump to solution
02-13-2018 01:28 PM
deleted-user-jxpbpbjlZInj
Occasional Contributor

Has anyone tried using Survey123 barcode type to scan the barcodes on the backs of drivers licenses (the PDF417 type?) Would love to see an example of the xls form to do so... 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
erica_poisson
Occasional Contributor III

@thesweenis - 

You can use custom JavaScript functions in your survey to parse a scanned drivers license into your Survey123 form. It works well, although sometimes the actual scanning process is a bit slow (still). 

Here is the js function which gets saved in your survey's "scripts" folder. 

    function DL2JSON (data) {
        var m = data.match(/^@\n\u001e\r(A....)(\d{6})(\d{2})(\d{2})(\d{2})/);
        if (!m) {
            return null;
        }

     

        var obj = {
            header: {
                IIN: m[2],
                AAMVAVersion: parseInt(m[3]),
                jurisdictionVersion: parseInt(m[4]),
                numberOfEntries: parseInt(m[5])
            }
        };

     

        for (var i = 0; i < obj.header.numberOfEntries; i++) {
            var offset = 21 + i * 10;
            m = data.substring(offset, offset + 10).match(/(.{2})(\d{4})(\d{4})/);
            var subfileType = m[1];
            var offset = parseInt(m[2]);
            var length = parseInt(m[3]);
            if (i === 0) {
              obj.files = [ subfileType ];
            } else {
              obj.files.push(subfileType);
            }
            obj[subfileType] = data.substring(offset + 2, offset + length - 1).split("\n").reduce(function (p, c) {
                p[c.substring(0,3)] = c.substring(3);
                return p;
            }, { } );
        }

     

        if (obj.DL) {
            ["DBA", "DBB", "DBD", "DDB", "DDC", "DDH", "DDI", "DDJ"].forEach(function (k) {
                if (!obj.DL[k]) return;
                m = obj.DL[k].match(/(\d{2})(\d{2})(\d{4})/);
                if (!m) return;
                obj.DL[k] = (new Date(m[3] + "-" + m[1] + "-" + m[2])).getTime();
            } );
        }

     

        return JSON.stringify(obj);
    }

 

Here is the syntax for your XLSform which will parse the information into your form:

erica_tefft_0-1647442513343.png

 

Erica

View solution in original post

5 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Sunny,

The barcode scanner component used by Survey123 does have the ability to parse PDF417 barcodes (the type used in driver's licenses).  That being said, we've seen poor performance as it is a fairly dense encoding and the information returned will need further processing to be useful (you can't, for example, right now extract just the date of birth from what is returned).

0 Kudos
erica_poisson
Occasional Contributor III

HI James,

Is there any planned improvement to the functionality of scanning PDF417/license barcodes in an upcoming release of Survey123?

Thanks,

Erica

Erica
thesweenis
New Contributor

James

Has there been any progress on this over the last 4 years?

Thanks

Mike 

0 Kudos
erica_poisson
Occasional Contributor III

@thesweenis - 

You can use custom JavaScript functions in your survey to parse a scanned drivers license into your Survey123 form. It works well, although sometimes the actual scanning process is a bit slow (still). 

Here is the js function which gets saved in your survey's "scripts" folder. 

    function DL2JSON (data) {
        var m = data.match(/^@\n\u001e\r(A....)(\d{6})(\d{2})(\d{2})(\d{2})/);
        if (!m) {
            return null;
        }

     

        var obj = {
            header: {
                IIN: m[2],
                AAMVAVersion: parseInt(m[3]),
                jurisdictionVersion: parseInt(m[4]),
                numberOfEntries: parseInt(m[5])
            }
        };

     

        for (var i = 0; i < obj.header.numberOfEntries; i++) {
            var offset = 21 + i * 10;
            m = data.substring(offset, offset + 10).match(/(.{2})(\d{4})(\d{4})/);
            var subfileType = m[1];
            var offset = parseInt(m[2]);
            var length = parseInt(m[3]);
            if (i === 0) {
              obj.files = [ subfileType ];
            } else {
              obj.files.push(subfileType);
            }
            obj[subfileType] = data.substring(offset + 2, offset + length - 1).split("\n").reduce(function (p, c) {
                p[c.substring(0,3)] = c.substring(3);
                return p;
            }, { } );
        }

     

        if (obj.DL) {
            ["DBA", "DBB", "DBD", "DDB", "DDC", "DDH", "DDI", "DDJ"].forEach(function (k) {
                if (!obj.DL[k]) return;
                m = obj.DL[k].match(/(\d{2})(\d{2})(\d{4})/);
                if (!m) return;
                obj.DL[k] = (new Date(m[3] + "-" + m[1] + "-" + m[2])).getTime();
            } );
        }

     

        return JSON.stringify(obj);
    }

 

Here is the syntax for your XLSform which will parse the information into your form:

erica_tefft_0-1647442513343.png

 

Erica
bsklaohfl
New Contributor III

Hi!

I realize this is an old post but I am curious if someone can assist me with the Javascript for the AAMVA PDF 417 for Florida. I have exhausted all "help" resources.

When scanning, my barcode returns as follows (private info removed):

@ ‑ ANSI 636010090002DL00410264ZF03050075DLDAQS123456789123 DCSLASTNAME DDEN DACFIRSTNAME DDFN DADMIDDLENAME DDGN DCAE DCBNONE DCDNONE DBDDATEOFDL DBBDOB DBAEXPIRATION DBC2 DAU067 IN DAGADDRESS DAICITY DAJFL DAKZIP DCFF1234 DCGUSA DCK1234 DDAF DDB1234 DDK1 ZFZFA20220906 ZFB ZFCSAFE DRIVER ZFD ZFE ZFF ZFG ZFH ZFI ZFJ0246553392 ZFK

 

I adjusted the function DL2JSON as follows:

function DL2JSON (data) {
var m = data.match(/^@\-\(A....)(\d{6})(\d{2})(\d{2})(\d{2})/);
if (!m) {
return null;
}

 The error message I receive is:

javascript error:TypeError: Property 'match' of object [object Object] is not a function in aamva.js:DL2JSON

The plus side of this setback is I've learned a fair bit about Javascript basics, but not enough to solve my issue! Thank you in advance!

Brooke

0 Kudos