java script to place file name in document as text doesn't update when file name changes

Aug 08, 2018

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

96

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

java script to place file name in document as text doesn't update when file name changes

Aug 08, 2018

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

97

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 08, 2018 0
Aug 08, 2018

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/,"");

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 08, 2018 0