Skip to main content
Inspiring
April 3, 2024
Answered

Embed the file name into the field

  • April 3, 2024
  • 2 replies
  • 1308 views

Hi everyone,

I have a question that may seem trivial, but I'm wondering if it's possible to synchronize the file name with a field within a PDF form. For example, if the file name changes, could it automatically update the assigned field within the form? If this is possible, any guidance would be greatly appreciated.

Thanks a lot.

This topic has been closed for replies.
Correct answer Thom Parker

But using the Did Save event will make the file "dirty", which will mean the user will need to save it again, and so on and so on. I think doing it when the file is opened is a better option.


Except that the field isn't update when the change is made. Good point about the dirty flag. 

Here's a redo of the script:

this.getField("FileNameField").value = this.documentFileName;

this.dirty = false;

 

 

2 replies

Bernd Alheit
Community Expert
April 3, 2024

You can use a script at document open.

KaxkulAuthor
Inspiring
April 3, 2024

Thank you @Bernd Alheit I tried this but didn't work either, not sure what I'm doing wrong?


function setFieldValueOnOpen() {
var fileName = this.path.replace(/^.*[\\\/]/, '');

this.getField("FileNameField").value = fileName;

this.calculateNow();
}

setFieldValueOnOpen();

KaxkulAuthor
Inspiring
April 3, 2024

I tried to apply the following:

 

function setFieldValueOnOpen() {
var fileName = this.path.replace(/^.*[\\\/]/, '');

this.getField("FileNameField").value = fileName;

this.calculateNow();
}this.setAction("WillSave", "setFieldValueOnOpen()");

 

But still, the field doesn't update automatically when the file is opened