Skip to main content
Participating Frequently
Feb 14, 2025 3:49 PM UTC
Question

Creating scripts in Adobe forms.

I'm not the greatest at writing scripts. I've inherited a form that I'm trying to update and I could use some help.  

1. In one of the fields, they will be scanning a barcode and the scan will have an equal sign at the beginning of the scan and two zeros at the end of the scan (e.g. =W28132020546700) that I need a script that will automatically delete those in the field. Final result would look like this W2813 20 205467

2.  In another field I have the age. I need a script that will use the DOB field to calculate the age in the AGE field.

3. in another field, they will be scanning an expiration date. The scan will display something like this "

&>0253652359" but I need a script that will convert that to 12/31/2025 23:59.

4. Then lastly, I need a script that will take another scanned value (e.g. =<E0713V00) and remove the leading =< and the trailing 00 and just display E0731.

 

I know it's a lot to ask but I could really use some help. 🙂

 

Thanks!

 

Val

11 replies

Nesa Nurani
Community Expert
Community Expert
Feb 14, 2025 4:21 PM UTC

For number 1, try something like this as custom format script:

if (event.value) {
 event.value = event.value.replace(/^=/, "");
 event.value = event.value.slice(0, -2).replace(/^(W\d{4})(\d{2})(\d+)$/, "$1 $2 $3");}
Translate
LEVELHEADAuthor
Participating Frequently
Feb 14, 2025 5:45 PM UTC

I can't figure out why...when I put that script in there and click OK, it doesn't save the information. 😞

Translate
PDF Automation Station
Community Expert
Community Expert
Feb 14, 2025 3:57 PM UTC

You should ask each question in separate posts.  For point one, is that a field value?

Translate
LEVELHEADAuthor
Participating Frequently
Feb 14, 2025 5:43 PM UTC

It is a Text Field

Translate
PDF Automation Station
Community Expert
Community Expert
Feb 14, 2025 6:52 PM UTC

Enter the following custom calculation script:

var aray=event.value.split("");
if(aray[aray.length-1]=="0"){aray.pop()};
if(aray[aray.length-1]=="0"){aray.pop()};
event.value=aray.join("").replace("=","");

Translate