Solution Timeline

All versions (edits) of solutions to Save As Function PDF appear below in the order they were created. Comments that appear under revisions were those created when that particular revision was current.

To see the revision history of a single solution (with diffs), click on the solution number (ie. "#1") in the upper right corner of a solution revision below.

← Bounty Expand all edits

Am not sure if i understood your question well but try out the code below.

put this in your document script...

function doSaveFile() {

 if (app.alert({cMsg: "Do you wish to save this document?",nIcon:2, nType: 3}) == 4){
// build file name
var newFileName = this.getField("textfield1").value + "." + this.getField("textfield2").value + "." 
+ this.getField("textfield3").value+"."+this.getField("textfield4").value+ "." +this.getField("textfield5").value+".pdf";

// Split the current path into an array so that we can remove the current file name
    var curPath = this.path.split("/);

    // Remove current file name
    curPath.pop();

    // Add our new file name to the array
    curPath.push(NewFileName);

    // Glue back together our array to get our new path
    var newPath=curPath.join("/");

    app.beginPriv();  
    var checkFlag = app.openDoc({ cPath: newPath, bHidden: true }); 
    app.endPriv();
    if(checkFlag)
    {
        app.alert({cMsg: "File already exists...",cTitle: " File save error"});
    }
    else
    {
        this.saveAs(newPath);
    }
}

}

put this in your button's mouseUp event...

doSaveFile();

Incase of anything let me know.

Am not sure if i understood your question well but try out the code below.

put this in your document script...

function doSaveFile() {

 if (app.alert({cMsg: "Do you wish to save this document?",nIcon:2, nType: 3}) == 4){
// build file name
var newFileName = this.getField("textfield1").value + "." + this.getField("textfield2").value + "." 
+ this.getField("textfield3").value+"."+this.getField("textfield4").value+ "." +this.getField("textfield5").value+".pdf";

// Split the current path into an array so that we can remove the current file name
    var curPath = this.path.split("/");

    // Remove current file name
    curPath.pop();

    // Add our new file name to the array
    curPath.push(NewFileName);

    // Glue back together our array to get our new path
    var newPath=curPath.join("/");

    app.beginPriv();  
    var checkFlag = app.openDoc({ cPath: newPath, bHidden: true }); 
    app.endPriv();
    if(checkFlag)
    {
        app.alert({cMsg: "File already exists...",cTitle: " File save error"});
    }
    else
    {
        this.saveAs(newPath);
    }
}

}

put this in your button's mouseUp event...

doSaveFile();

Incase of anything let me know.

In mashtullah's solution, I believe you want a confirmation if the file exists, and then the user can select whether they want to continue with the saving or not. In that case, you can replace the last if statement with this one

if(checkFlag){
    if (app.alert({cMsg: "File Already Exists. Save anyway?", nIcon: 1, cTitle: "File Exists", nType: 2}) == 4){
          this.saveAs(newPath);      
    }
}   
else{
    this.saveAs(newPath);
}

Am not sure if i understood your question well but try out the code below.

put this in your document script...

function doSaveFile() {

 if (app.alert({cMsg: "Do you wish to save this document?",nIcon:2, nType: 3}) == 4){
// build file name
var newFileName = this.getField("textfield1").value + "." + this.getField("textfield2").value + "." 
+ this.getField("textfield3").value+"."+this.getField("textfield4").value+ "." +this.getField("textfield5").value+".pdf";

// Split the current path into an array so that we can remove the current file name
    var curPath = this.path.split("/");

    // Remove current file name
    curPath.pop();

    // Add our new file name to the array
    curPath.push(NewFileName);

    // Glue back together our array to get our new path
    var newPath=curPath.join("/");

    app.beginPriv();  
    var checkFlag = app.openDoc({ cPath: newPath, bHidden: true }); 

    if(checkFlag)
    {
        app.alert({cMsg: "File already exists...",cTitle: " File save error"});
    }
    else
    {
        this.saveAs(newPath);
    }
   app.endPriv();
}

}

put this in your button's mouseUp event...

doSaveFile();

Incase of anything let me know.