• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Use Save As button to create unique file name from form fields

Community Beginner ,
Dec 16, 2024 Dec 16, 2024

Copy link to clipboard

Copied

Hello,

 

I have a form that I've added a button to that needs to pull from form fields and save the file with those field names to create a unique file name.

I've read the old post on this topic:

Solved: Save PDF File Name as Field Name in PDF - Adobe Community - 7231510

However, it's not working for me. 

Steps I've taken:

1. Created JS file in the user directory for the trusted function C:\Users\Username\AppData\Roaming\Adobe\Acrobat\Privileged\DC\JavaScripts (this is for work and I don't have administrator access to save in the JS folder). 

2. Copied the JS file into the folder where the PDF lives

3. File contains script:

 

var mySaveAs = app.trustedFunction(function(oDoc, cPath, cFlName) {
FILE PATH REMOVED PER USER'S REQUEST

Sandbox/22178_Fillable 1_Out - 5 Sandbox Save to Folder.pdf/
cPath = cPath.replace(/([^/])$/, "$1/");
try {
app.beginPriv();
oDoc.saveAs(cPath + cFlName);
app.endPriv();
} catch (e) {
app.alert("Error During Save - " + e);
}
}
);

4. Added button to my form

5. Set button to run a Javascript with the following script:

 

// determine the directory path for the current document
var directory = this.path.substring(0, this.path.lastIndexOf('/') +1);
if (typeof(mySaveAs) == "function") {
mySaveAs(this, directory, this.getField("FirstName").value + " " + this.getField("LastName").value + " " + this.getField("DateofCalldd-Mon-yyyy").value + ".pdf");
} else {
app.alert("Missing Save Function. Please contact forms administrator ");
}

 

When I click the button, I get the following error message in the debugger

TypeError: this.getField(...) is null
4:Field:Mouse Up

 

Thanks for any help on this!

TOPICS
General troubleshooting , How to , JavaScript , PDF , PDF forms

Views

118

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
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Dec 16, 2024 Dec 16, 2024

Copy link to clipboard

Copied

That error means one of the fields referenced in your script does not exist.  Check the field name spellings of the fields carefully against the field names in the script, including case sensitivity.  The 4 is line 4 so it's probably this field:

DateofCalldd-Mon-yyyy

View solution in original post

Votes

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
community guidelines
Community Expert ,
Dec 16, 2024 Dec 16, 2024

Copy link to clipboard

Copied

That error means one of the fields referenced in your script does not exist.  Check the field name spellings of the fields carefully against the field names in the script, including case sensitivity.  The 4 is line 4 so it's probably this field:

DateofCalldd-Mon-yyyy

Votes

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
community guidelines
Community Beginner ,
Dec 16, 2024 Dec 16, 2024

Copy link to clipboard

Copied

LATEST

Thank you! This worked for me now. I had an error in the last field

Votes

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
community guidelines