Highlighted

Trying to auto generate save file name from fillable field values, but there 'undefined' is added.

Community Beginner ,
Jun 24, 2020

Copy link to clipboard

Copied

So I have successfully generated a file save name but 'undefined' is added to the front. So in the code shown below i have the date as my file name so instead of 'YYYYMMDD.pdf' being saved, 'undefinedYYYYMMDD.pdf' is being saved instead.  Any ideas why that is?

 

// get the value of the form field
var text1Value = this.getField("DATE").value;

 

// here you need to make sure that no illegal characters are used, and also that //text1Value is not empty

// make a file name from the field value


var newFileName = text1Value + ".pdf";

//console.println(newFileName);


// get the path where the file is currently located
var filePath = this.path.replace(this.documentFileName);

// create the new full path
var newFullFilePath = filePath + newFileName;

//console.println(newFullFilePath);

try {
this.saveAs(newFullFilePath); // Only this will not work from a button...
} catch (e) {
app.alert("Error! Could not save as: " + newFullFilePath);
}

undefined

 

Topics

Comment review and collaborate PDF, Edit and convert PDFs, General troubleshooting, PDF forms

Views

52

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

Trying to auto generate save file name from fillable field values, but there 'undefined' is added.

Community Beginner ,
Jun 24, 2020

Copy link to clipboard

Copied

So I have successfully generated a file save name but 'undefined' is added to the front. So in the code shown below i have the date as my file name so instead of 'YYYYMMDD.pdf' being saved, 'undefinedYYYYMMDD.pdf' is being saved instead.  Any ideas why that is?

 

// get the value of the form field
var text1Value = this.getField("DATE").value;

 

// here you need to make sure that no illegal characters are used, and also that //text1Value is not empty

// make a file name from the field value


var newFileName = text1Value + ".pdf";

//console.println(newFileName);


// get the path where the file is currently located
var filePath = this.path.replace(this.documentFileName);

// create the new full path
var newFullFilePath = filePath + newFileName;

//console.println(newFullFilePath);

try {
this.saveAs(newFullFilePath); // Only this will not work from a button...
} catch (e) {
app.alert("Error! Could not save as: " + newFullFilePath);
}

undefined

 

Topics

Comment review and collaborate PDF, Edit and convert PDFs, General troubleshooting, PDF forms

Views

53

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
Adobe Community Professional ,
Jun 24, 2020

Copy link to clipboard

Copied

 Use this:

var filePath = this.path.replace(this.documentFileName, "");

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...
Resources
One Stop Solution for Acrobat
Edit a PDF