Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

How do I parse data from a QR Barcode scan and then do a DB write?

I have succeeded in getting the barcode scanner to work and it is outputting text in the following format:

BEGIN:VCARD VERSION:2.1 FN:Chris Herold TEL;work:888-919-0919 EMAIL;INTERNET;work:a href="mailto:msacl@gmail.com" rel="nofollow"msacl@gmail.com/a END:VCARD

How do I:
(1) parse this information (name, phone, email), and then
(2) send it to the Appery database that I have set up?

Thank you!
chris

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How do I parse data from a QR Barcode scan and then do a DB write?

Hi Christopher,

It would be better to encode structured data in QR. For example, you can use the rule to separate all the data with a semicolon.

Without this, it's too difficult to create a good parser.

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

How do I parse data from a QR Barcode scan and then do a DB write?

Hi Katya,

The data is the same format every time. I just need to know how to write it to specific variables using javascript (?) that I can then put into my database.

I am trying to use javascript to pull out the name from the VCARD data (see top of thread), specifically using
code
return '{ "+value+".match(/FN:(.+?)TEL/)[1] }';
/code
within the variable that I am writing to. For instance, I am sending the full_text of the VCARD to 'name' in the database, but in the Add JS option of 'name' I am including the above. My hope was that the full_text value would be substituted as "+value+" and then the match would pull out the name and put it in the database. Instead I literally put { "+value+".match(/FN:(.+?)TEL/)[1] } into the database.

Any idea what I am doing wrong?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How do I parse data from a QR Barcode scan and then do a DB write?

Hi Christopher,

If I understand you correctly you should add this code to the mapping to localSorage variable. Then, on Complete event you call another service that saves this localStorage variable value in Database.

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

How do I parse data from a QR Barcode scan and then do a DB write?

Hi Katya,

I have changed the positioning of the javascript, but I still am getting the literal return of { "+value+".match(/FN:(.+?)TEL/)[1] }. The javascript is not being processed. I am not a javascript expert and looking on the web I have not found any helpful solution.

Could you please tell me if I am using the correct javascript code to pull the information out? Do I have some quotes in the wrong place(s). I tried it without the single quotes outside of the curly brackets, but that seemed to paralyze the app in testing.

The code that I am putting in the local storage variable is below.

code
return '{ "+value+".match(/FN:(.+?)TEL/)[1] }';
/code

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

How do I parse data from a QR Barcode scan and then do a DB write?

Hi Katya,

I moved the code to the local variable instead, as you recommended, and I am still having the same problem where the code itself seems to be getting written to the database.

This gets written to the database: { "+value+".match(/FN:(.+?)TEL/)[1] }

Are you able to tell me what is wrong with the javascript below that leads to this? I have tried taking out single quotes on the outside, but that seems to paralyze the app.

code
return '{ "+value+".match(/FN:(.+?)TEL/)[1] }';
/code

Thanks!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How do I parse data from a QR Barcode scan and then do a DB write?

Hi Christopher,

This is the correct code:
codereturn value.match(/FN:(.+?)TEL/)[1];/code
The symbols " and ' differ, so you should always use them in pair, for example "string" or 'string' (but not "string').

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

How do I parse data from a QR Barcode scan and then do a DB write?

Hi Katya,

I tried the code you suggested above and it doesn't seem to work.

The code below works (with the explicit text), but for some reason, the "value" term in the code that you suggested above is not pulling the text into the javascript function. I know the text is coming into the field because without the javascript it is outputted to the screen. Any ideas on what I am doing wrong?

code
return "BEGIN:VCARD VERSION:2.1 FN:Chris Herold TEL;work:888-919-0919 EMAIL;INTERNET;work:msacl@gmail.com END:VCARD".match(/FN:(.+?)TEL/)[1];
/code

Thanks Katya!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How do I parse data from a QR Barcode scan and then do a DB write?

Hi Christopher,

Do you use this code in mapping or run it on event?

Return to “Issues”