Skip to main content
michelled19159583
Known Participant
Jun 15, 2017 11:31 AM UTC
Question

Acrobat Adobe - Common Pulling Script

Hello,

I am working with Acrobat Adobe XI. I am naming field names so that they self populate throughout the document that I am working on. One of my values, Unique ID, is comprised of "purch_order""-""clin""-""body_sn". I was able to make a script that will pull the values for Unique ID from their respective fields and populate in the appropriate order.

Script:

event.value = this.getField("purch_order").value.toString().replace(/0/,"") + "-" + this.getField("clin").value.toString().replace(/0/,"") + "-" + this.getField("body_sn").value.toString().replace(/0/,"");

More info:

Script is used for the field name Unique ID

purch_order = Purchase Order

clin = Item Number

body_sn = Serial Number

The Problem:

The issue with my script is that it does not allow for leading and trailing zeroes. For the purchase order and serial number, I need to keep the leading and trailing zeroes included as they are part of the Unique ID. For the line item, I only need to keep the trailing zeroes, and I cannot keep the leading zeroes. For anyone wondering, the purchase order is comprised of 10 numbers/letters. The item Number is comprised of four numbers. And the serial number is comprised of 5 numbers/letters. I am defining numbers as 0-9. And letters as A-Z. Does anyone know how I can write a script within my script for each field name to keep/remove the trailing and leading zeroes that I require?

Any ideas would be much appreciated!

Thanks,

Michelle

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

michelled19159583
Known Participant
Jun 15, 2017 5:56 PM UTC

Hi try67 and Karl,

Thank you both so much for your replys. I really appreciate it!

I updated my script to be this:

var someVariable = (this.getField("purch_order").valueAsString().replace(/0/,"") + "-" + this.getField("clin").valueAsString().replace(/^0+/,"") + "-" + this.getField("body_sn").valueAsString().replace(/0/,""));

But, now it doesn't work.Any Ideas?

Thanks,

Michelle

Translate
try67
Community Expert
Community Expert
Jun 15, 2017 6:06 PM UTC

valueAsString is a property, not a function. Remove the parentheses after

it.

On Thu, Jun 15, 2017 at 7:57 PM, michelled19159583 <forums_noreply@adobe.com

Translate
try67
Community Expert
Community Expert
Jun 15, 2017 11:40 AM UTC

First of all, don't use the value property, but valueAsString. The former will strip any leading zeros...

What's missing in your code is a bit of RegExp magic. Namely, the control characters that indicate the start or end of a string.

So, to remove any leading zeros you can use this RegExp:

/^0+/

And to remove any trailing zeros use this one:

/0+$/

^ - The start of a string

$ - The end of a string

+ - Match one or more characters (in case there's more than one zero at the start/end of the string, I assume you want to remove them all, not just the first one)

Translate
Karl Heinz  Kremer
Community Expert
Community Expert
Jun 15, 2017 11:38 AM UTC

When you get the "value" of a field, it will interpret anything that looks like a number as a number - and that means that leading zeroes will get removed. Use the "valueAsString" property instead. This will preserve leading zeros:

var someVariable = this.getField("someName").valueAsString;

Translate