UPDATED 1/5/2022: We have an adobe acrobat form in which we created a "Save to share drive" button and have the completed form save to a designated folder on a share drive and create a file name based on certain fields in the form. We added a .js file to the javascript folder in the C: program files to allow save as. All of that is working fine HOWEVER if another person comes along and completes a form and selects the same fields, then the file name could be the same. The code prompts the 2nd user to overwrite file with same name or not, but it doesn't let you execute the not overwrite function.
How can we either altogether prevent an overwrite or do a saveAs with a slightly different name like with a (2) after it? We get the pop up saying "the file XXNAME already exists, Do you want to replace it?" If you click Yes on the pop-up, it overwrites the existing file. If you click No, it doesn't overwrite, but you get this message: "NotAllowedError: Security settings prevent access to this property or method. Doc.saveAs:3:Field SaveToShareDrive:Mouse Up"
Here is the JavaScript code saved in a .js file in the program files:
mySaveAs = app.trustPropagatorFunction(function(doc,path) { app.beginPriv(); doc.saveAs({cPath: path, bPromptToOverwrite: true}); app.endPriv(); })
myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path) { // Privileged and/or non-privileged code above app.beginPriv(); mySaveAs(doc,path); app.endPriv(); // Privileged and/or non-privileged code below });
Here is the JavaScript code on the "Save to Share Drive" button in the form itself:
// build file name
var myFileName = getField("CaseNameInRegardsTo").value + "-" + getField("Classification").value + "-" + getField("IrType").value + "-" +
getField("Initial").value + "-" + getField("SpecialRqstProgram").value + "-" + getField("SpecialRequestType").value + "-" + getField("ReportCounty").value + "-" +
getField("CompanionReports").value + "-" +
getField("SensitiveCase").value +
".pdf";
// add folder name
myFileName = "/S/swi/downtime/" + myFileName;
myTrustedSpecialTaskFunc(this, myFileName);
Hello Juan, I'm having an issue while running Button script. In javascript Debugger shows an error which is: ReferenceError: myTrustedSpecialTaskFunc is not defined 5:Field:Mouse Up
Is there anything missing in my javascript.
var myFileName = this.getField("bm1").value +"-" + this.getField("bm2").value +"-" + this.getField("bm3").value +"-" + this.getField("bm4").value +"-" + this.getField("bm5").value+ "-" + util.printd("dd-mm-yyyy hhmm", dt)+ ".pdf";
myFileName = "/c/test/" + myFileName
myTrustedSpecialTaskFunc(this, myFileName);
app.alert("This Form ( "+myFileName+" ) has saved successfully to the following location: /C/test/" , 3);