java script to place file name in document as text doesn't update when file name changes
Copy link to clipboard
Copied
I'm using a script I found online to place the file name of a PDF within the document itself (we use the file name as a purchase order number).
I have a text box with properties under the Format tab, format category Custom, Customer Format Script is
var name = this.documentFileName
name = name.substr(0, name.lastIndexOf('.'));
event.value = name;
When first entered as text field property it adds file name to the field (yay!), but when the file name is changed the text field doesn't update, just stays the same. We use the file name as a reference for a purchase order system, so it'd be nice if the bookkeeper could see what the file name was that printed the document.
Any ideas on how to get it to update the text field with the current file name, even when the file name changes?
Thanks,
Mike
Copy link to clipboard
Copied
Wrong location for the script, which is overly complicated. The correct place is in either a document script, which updates when the PDF is opened or the DidSave Script, which updates after the form is saved.
Here's a shorter version of the same script
this.getField("NameField").value = this.documentFileName.replace(/\.pdf/,"");
Use the Acrobat JavaScript Reference early and often

