Other PDF Issues

When to Use this.getField() or getField() in Acrobat JavaScript

John WilsonJohn Wilson Nov 19, 2026 868 views

Question details

Understand when to use this.getField() instead of getField() in Acrobat JavaScript.

When to Use this.getField() or getField() in Acrobat JavaScript
Product
Adobe Acrobat JavaScript
Device & OS
not provided
Scenario
Writing PDF form scripts at the document, field, page, or folder level.
Observed behavior
The script should retrieve a named field from the intended PDF document using a document reference appropriate to its execution context.
Before you start

Identify where the script runs and confirm the exact field name in Acrobat's Prepare a form tool. Check what this refers to in that context before using it as a document reference.

Solution 1Recommended

Use this.getField() in a document context

Use an explicit document reference when a document-level script needs to access a form field.

In document-level scripts, this normally refers to the current document, so this.getField("FieldName") makes the target explicit. An unqualified getField("FieldName") is commonly resolved against the current document in document, field, and page scripts, but its meaning depends on the execution context.

1
Open the document script

In Acrobat, open the PDF and use All tools > Use JavaScript > Document JavaScripts to create or edit a document-level script.

2
Reference the field

In the script editor, enter this.getField("FieldName"), replacing FieldName with the exact name shown in Prepare a form.

3
Test the script

Save the script and test it in Acrobat. Check that the returned field is not null before reading or changing its properties.

Use this.getField() in a document context
Check the context: Use this.getField() only when this is the document object. In a field event, event.target is typically the field; event.target.doc provides its document.
Free Microsoft Office alternative

Work with PDF and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Office files. Its format compatibility makes moving everyday documents easier; use Acrobat to develop or test Acrobat-specific JavaScript.

Open and work with PDF documents alongside Office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for navigating documents and spreadsheetsFree, lightweight option for everyday office work
microsoft office alternative - wps office

Frequently Asked Questions

Are this.getField() and getField() always equivalent?

No. They may resolve to the same document in common document, field, and page script contexts, but this.getField() works only when this refers to the intended document.

How do I get the document from a field event?

When event.target is the field, use event.target.doc to access its document, then call event.target.doc.getField("FieldName").

Why does getField() return null?

The named field may not exist in the document being searched. Check the exact field name in Acrobat's Prepare a form tool and verify that your document reference points to the intended PDF.

Can I use this.getField() in a folder-level script?

Only if this refers to the intended document at the time the code runs. A safer pattern is to pass a document object into the folder-level function and call doc.getField("FieldName").