Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Barcode scanning into non Multi-Line Fields

Community Beginner ,
Aug 09, 2021 Aug 09, 2021

Copy link to clipboard

Copied

I have an adobe form created with a VR Mapping script (shown below):

 

var mapping = {
1 : 3000,
2 : 4500,
3 : 5000,
};

var v1 = this.getField("Barcode Number").value;
var v2 = mapping[v1];
if(v2 != undefined){
event.value = v2;
}
else {
event.value = "Enter Barcode Number / Barcode Error";
}

 

To basically recognise a barcode number entered into the "Barcode Number" feild, and then genarate the accosiated package number into the "Package Number" feild. If I manually enter the barcode number and click 'Return', the "Package Number" feild populates as per the script. (example - entering the number 1 in the "Barcode Number" feild returnes a value of '3000'). Note that the "Barcode Number" feild is set to Multi Line (OFF).

 

However if I try to scan a barcode with the data number "1" using a basic USB scanner into the "Barcode Number" feild, it does not pull the data through. The only way that I can get the barcode number to pull from the scanner is to chage the feild properties to enable 'Multi-Line'. However, when 'Multi-Line' is enabled, clicking return moves the cursor onto the next line (as expected). But this means that the script will not run and the "Package Number" feild does NOT populate as per the script. 

 

I suppose my questions are:

1. Is there an error in my script which is preventing it from working with a feild that has 'Multi Line' enabled?

2. Is there a way to allow a scanner to pull barcode data into a feild which has 'Multi-Line' DISABLED.

As always, thank you for your assitance!

 

TOPICS
JavaScript, PDF forms

Views

56

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

I cannot think of a good reason why it would work with multi-line enabled, but not with it being disabled. Is it possible that your scanner reports more than just a single digit (which is what you expect, based on your script)? How do you get informatkion from the scanner into a field? Acrobat does not have barcode scanner integration, so I assume the scanner is emulating a keyboard, is that correct? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

Hi Karl, glad you have replied, as it is your script I have used. The scanner is just emulating a keyboard input. with a CR after the scan. Scannig the number into MS Word acts as expected, scans over the number and then simulates pressing enter.

I have attached an example file. So entering the number "1" into the scanner input box and pressing 'enter' should ouput package number 1000. 

 

Ideally I would like to just do a VLOOKUP from an excel spreadsheet, but not sure if this is possible? as your script is the closest I coould find.

 

Thank you!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

In which context are you running the script? Is it a custom validation script? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

I have it in a Custom Calculation Script at the moment in the relvant feild. Is that not correct?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

Before I go into answering your question, can you program the scanner to produce a different character to commit the value? If so, what happens if you use the TAB character?

 

Back to your question: There are different ways to accomplish this. When you fill in your form manually, it usually does not matter which way you pick, as long as you end up with the correct behavior, in this case, it may make a difference. 

 

A custom calculation script only run after the value in the first field is committed. By using a validation script, we may be able to get around this limitation (assuming that it is causing the different behavior between the one line vs. the multi-line field).

 

Here is what I would do to figure out what's going on: I would create debug output to find out what scripts are being run at what time, and with what information available in the barcode field. 

 

Add one line to your custom calculation script:

 

var mapping = { 

1 : 1000,
2 : 2000,
3 : 3000,

};

var v1 = this.getField("SI 2").value;
console.println("|" + v1 + "|");
var v2 = mapping[v1];
if(v2 != undefined){
    event.value = v2;}
else {event.value = "Incorrect Barcode";}

 

This will show what gets actually read from the field. Try this first, and then we go from there. This should print a "|" followed by the value, followed by another "|". If there is anything between the two "|" besides the one digit, then we know what is causing the problem - and we can work on that. If this test is inconclusive, we test something different in the next step. 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

Hi Karl, That didn't work. entering the nnumber '1' into the feild with multi line enabled and pressing enter does not return the value of 1000. But entering the number '1' into the file with multi line disabled and then pressing TAB, does return the value of 1000. So I tried this with the barcode scanner using a barcode with a value of '1' and a TAB at the end. Tested in in MS Word first, and the scanner puts the number '1' into the document and inserts a TAB after it. Tried it in adobe and thwe scanner will not pull the number '1' into the form using the scanner. That is for both the multi line enabled and disabled feilds.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

I would not have expected the tab to work with the multi-line field, but with the single line, it should tab out of the field and to the next field. Did you try the modified code that I posted to see what you are actually getting from the first field after the barcode scanner does it's job? You will have to check the JavaScript console (ctrl-J or Cmd-J on a Mac will open the console). 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 08, 2021 Sep 08, 2021

Copy link to clipboard

Copied

Hi Karl,

 

I am still having a nightmare with the barcodes and adobe pro, hoping you could help if I sent you some files.

 

I have attached a file with the following feilds

 

PB1                PN1

PB 2               PN2

 

The PN feilds have the following custom calculation script

 

var mapping = {
1 : 3000,
2 : 4500,
3 : 5000,
};

var v1 = this.getField("PN1 OR PN2 FOR THIS EXAMPLE").value;
var v2 = mapping[v1];
if(v2 != undefined){
event.value = v2;
}
else {
event.value = "Enter Barcode Number / Barcode Error";
}

 

When I enter the nunmber 1, 2 ort 3 into feilds PB1 or PB 2 and click enter, the correct value shows in the corrosponding PN1 or PN2 feild.

 

When it comes to the barcodes, they just will not work with adobe. I have attached them into the pdf so you can see. I have formatted the barcodes with a '\n' after them to simulate a keyboard 'enter' input. This works when scanned into MS Word. 

 

Could you please have a look and see if you can shed any expert light? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 08, 2021 Sep 08, 2021

Copy link to clipboard

Copied

LATEST

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines