Fix the Acrobat JavaScript myDoc Is Undefined Error in PDF
Question details
The user is trying to resolve a 'myDoc is undefined' error that happens when executing a custom JavaScript action from a PDF button to open another PDF document.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Triggering a script via a PDF button action to open a secondary PDF and access its form fields.
- Observed behavior
- The JavaScript code works perfectly when run from the Acrobat console, but throws a 'myDoc is undefined' error when run from a button click due to strict security context restrictions.
Make sure you have editing permissions for both the source and target PDF documents, and verify that Acrobat's JavaScript execution preferences are enabled in your settings.
Disclose Target Document and Validate the Object
Adjust the target document's security properties to allow cross-document script access, then properly validate the document object in your button script.
When you run scripts from the Acrobat console, they execute with elevated privileges. However, executing the same code from a PDF button triggers a restricted, user-level security context. If the target document is not explicitly set to be 'disclosed', Adobe Acrobat will block access to its properties and fields to prevent malicious scripting, resulting in an undefined document object.
Open the target PDF document in Adobe Acrobat. You must set its disclosed property to true (e.g., using 'this.disclosed = true;' in its Document-Level JavaScript) so that scripts from other PDFs are permitted to read its fields.
Open your source PDF document, enter Form Editing mode, right-click the button that triggers the script, and select 'Properties'. Navigate to the 'Actions' tab and edit the 'Run a JavaScript' action.
Modify your button script to ensure 'app.openDoc()' successfully returns a document object before calling 'getField()'. Add a validation step like: 'var myDoc = app.openDoc("target.pdf"); if(myDoc != null) { // Access fields safely here }'.

Try WPS Office for a Streamlined PDF Experience
Dealing with complex Adobe Acrobat JavaScript errors can disrupt your workflow. If you are looking for a reliable, easy-to-use alternative for standard PDF editing, document conversion, and form filling without the need to write or debug code, WPS Office is an excellent choice.
- 1. Download WPS Office: Visit the official WPS website to download the free, lightweight installer for your operating system.
- 2. Install and Launch: Follow the straightforward on-screen instructions to install the suite, then open WPS PDF.
- 3. Edit Your PDF: Drag and drop your PDF files into the application to instantly merge, fill, or sign documents without needing advanced scripts.

Frequently Asked Questions
Why does my Acrobat JavaScript work in the console but fail on a button click?
The Acrobat JavaScript console operates with administrative privileges, bypassing many cross-document security checks for debugging purposes. Button actions, however, execute in a restricted user sandbox where cross-document scripting is blocked by default.
What is the 'disclosed' property in a PDF document?
The 'disclosed' property is an internal PDF security setting that, when set to true, allows the document's structure and form fields to be accessed by scripts executed from entirely different PDF documents.
How do I check my JavaScript security settings in Adobe Acrobat?
Navigate to Edit > Preferences (or Acrobat > Settings on macOS). Select 'JavaScript' from the categories pane on the left, and ensure that 'Enable Acrobat JavaScript' is checked. For cross-document functions, you may also need to review specific trust privileges in the 'Security (Enhanced)' tab.




