Copy link to clipboard
Copied
I am trying to run a date stamp script through action wizard, which works when run on a single file through the console. The script is
for (var p = 0; p < this.numPages; p++) {var f = this.addField("Date", "text", p, [350, 770, 600, 790] ); f.value = "Document Received: " + util.printd("mm/dd/yy hh:MM:sstt", new Date());}
When run I get the error InvalidDocumentError: Method called on invalid document objec: document.addField().
Thanks for the help!
Copy link to clipboard
Copied
Before for loop add this lines:
console.show();
console.println(this.path);
Then you can see where the action stops.
Copy link to clipboard
Copied
I added the lines and ran it and it output 4: which I assume means the script failed on the fourth line which is var f = this.addField("NextPage", "text", p, [350, 770, 600, 790] ); I believe it is an issue with the this.addField, but this is my first time using javascript and I am unfamiliar with how this interacts.
Copy link to clipboard
Copied
Check the document where it stops.
Copy link to clipboard
Copied
It stops at the first document
Copy link to clipboard
Copied
Run the script in the console.
Copy link to clipboard
Copied
It works fine in the console, which is why I am confused when it fails when doing multiple files.
Copy link to clipboard
Copied
Can you share the document?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Works fine for me. What other commands did you add to the Action?
Copy link to clipboard
Copied
No problem with this file.
Copy link to clipboard
Copied
That's the only action I'm performing.
Copy link to clipboard
Copied
Well, thanks for the help, I thought there was an issue with the code that I did not understand, but now I know the code is all right, it seems to be an issue with the version I'm running.
Copy link to clipboard
Copied
Repair the Acrobat Installation.
Copy link to clipboard
Copied
Well, you should at least add a command to save the file after executing the JS code...
Copy link to clipboard
Copied
Acrobat is having a problem with the "this" keyword. In most cases "this" is a pointer to the current document, which in a batch process is supposed to be the document currently being processes. However there's definately a problem with "this". It's saying the document is invalid. This usually happens when using a doc object after the actual document is closed.
The real pointer to the current object in batch process is "event.target", try replacing "this" with "event.target"