Skip to main content
kenneth kam chuh21426993
Known Participant
April 28, 2025
Question

How to Save file name as field name once document is signed

  • April 28, 2025
  • 2 replies
  • 353 views

I have the following document level Javascript written, which I'd like to execute when the document is signed. This script should save the file as the field name ("BatchNumber") with a suffix "_signed" . The file is saved in the current folder. 

e.g. "20250428_signed"

// Document-level JavaScript
function saveWithFieldName() {
    var fieldName = this.getField("BatchNumber").value; // Grab the value from the field
    if (!fieldName) { // Corrected: check the value, not the field name
        app.alert("Field is empty. Cannot save.");
        return;
    }
    try {
        var path = this.path.replace(this.documentFileName, ""); // Get current folder
        var saveFileName = fieldName + "_signed.pdf"; // Add _signed suffix
        var savePath = path + saveFileName;
        this.saveAs(savePath);
        app.alert("File saved as: " + saveFileName);
    } catch (e) {
        app.alert("Error saving file: " + e);
    }
}

I then call or the function in the "Signed" properties. 

 

However, when I signed this document, it does not automatically rename the file like I want it to....

any idea why? 

 

 

2 replies

try67
Community Expert
Community Expert
April 28, 2025

Even if you did save the file silently under the desired name, the user will still get the Save As dialog immediately after signing the file. There's no way around that.

PDF Automation Station
Community Expert
Community Expert
April 28, 2025

Saving 'silently' (without user interaction) is privileged.  It must be run from the console, an Action, or a trusted function in a folder level script.

kenneth kam chuh21426993
Known Participant
April 28, 2025

Is there any way I can overcome this problem without a folder level script? 

PDF Automation Station
Community Expert
Community Expert
April 28, 2025

The user will have to copy and paste the file name to a SaveAs window like this:

app.response("Copy File Name:","",this.getField("BatchNumber").value);
app.execMenuItem("SaveAs");