Skip to main content
Santiman21
Known Participant
February 25, 2019
Answered

Save As Function

  • February 25, 2019
  • 1 reply
  • 1413 views

My goal is to create an automated Save As function (utilizing a button or something on the document) that will save the document to the same location as the original file, as well as rename the file by reading certain fields on the document.

An example of what I would want the save file to look like would be:

LastName.FirstName.IDnumber.ReasonForVisit

The last name, first name, and ID number are text fields that would have those obvious details entered and the reason for visit would be one (or multiple) of various check boxes that would have an export value. I wanted to know if it is possible to do something like this, as well as putting a "." between each of the details to make it easier for sorting/searching purposes.

I know this would include a folder level script, I also wanted to know if there is a file level script needed or if the call script would only be attached to the button created. I would also like it to prompt the user if there is already a file with the same name (to overwrite or not)

I know how to find different paths, etc, I am just a little unsure of how to save to the same path that the document is currently in (as some users may use different locations to save/store these files), I also know that the field names would be used in the script, etc, I just don't know how best to structure the script and so on.

This topic has been closed for replies.
Correct answer try67

This is exactly what I was trying to figure out. Thank you. So is it possible then to use the getfield function to use the export value of a checkbox to fill in part of the file name? The various checkboxes would be used to indicate the reason for the person's visit, the save file name would preferably reflect it as well.


Yes, it's exactly the same for a check-box as for a text field. The only difference is that the default value of a check-box (when it's not ticked) is always "Off".

1 reply

try67
Community Expert
Community Expert
February 25, 2019

- Yes, you can add a period between the values, simply by using the + operator between them and putting the period character in quotes.

- You don't need a doc-level script, if that's what you're asking. The script can be located entirely under the button, which calls the folder-level script with the correct parameters (such as the desired file name and path).

- Finding out if a file with the same name already exists is not simple, nor always possible. To do it you would need to attempt to open the file with that name, and then check the return value. If it's not null then you know that a file with that name exists, but for that to happen the file must be disclosed. Alternatively, you can specify the bPromptToOverwrite parameter as true, and then the user will be prompted if a file with that path exists.

- To save to the same path of the original document you can use something like this:

var newFileName = "Whatever.pdf";

var newFilePath = this.path.replace(this.documentFileName, newFileName);

this.saveAs(newFilePath);

Santiman21
Known Participant
February 25, 2019

This is awesome help. Thank you. The prompt to overwrite is what I was looking for. How would I get the save name to call from the various fields? Is it possible to use an export value for a checked check box as part of the file name too? All of these parameters would go into the folder level script right? How would I get the button to call the script?

I've never dealt with trusted functions.

try67
Community Expert
Community Expert
February 25, 2019