Skip to main content
Participant
June 4, 2024
Answered

Create a Save As button in a form that calls on a field for its file name

  • June 4, 2024
  • 1 reply
  • 2198 views

Looking at assistance to create a SAVE AS button in a form, I am wanting it to pre populate the File Name from a field within the form. Is this possible and if so, how? I have been searching for the answer with no luck.

This topic has been closed for replies.
Correct answer try67

Use this JS code:

app.execMenuItem("SaveAs");

1 reply

try67
Community Expert
Community Expert
June 4, 2024

You can't pre-populate the File Name field in the Save As dialog. You can either save the file silently using a specific path (but that requires running the code from a privileged context, such as a folder-level script), or you can open the Save As dialog with the current file name as the default.

PDF Automation Station
Community Expert
Community Expert
June 4, 2024

"You can't pre-populate the File Name field in the Save As dialog" - Not directly but there is a workaround when you combine app.browseForDoc (which reads 'Save As' in the popup window, with the file name prepopulated) with doc.SaveAs.  This requires a priviliged context as well.  Example:

try{var pth=app.browseForDoc(true,this.getField("File Name").value+".pdf").cPath}catch(e){var pth=null};
if(pth)
{this.saveAs(pth)}

 

 

try67
Community Expert
Community Expert
June 4, 2024

Why do you need browseForDoc for that? You can just specify the file-path directly.