title: How to prevent overwrite in acrobat form if it has the same file name created from form fields with automated mysaveas
body: <p>UPDATED 1/5/2022: We have an adobe acrobat form in which we created a &quot;Save to share drive&quot; 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.</p>
  <p>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 &quot;the file XXNAME already exists, Do you want to replace it?&quot; 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: &quot;NotAllowedError: Security settings prevent access to this property or method. Doc.saveAs:3:Field  SaveToShareDrive:Mouse Up&quot;</p>
  <p>Here is the JavaScript code saved in a .js file in the program files:</p>
  <pre><code>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 });
  </code></pre>
  <p>Here is the JavaScript code on the &quot;Save to Share Drive&quot; button in the form itself:</p>
  <pre><code>// build file name
  var myFileName = getField(&quot;CaseNameInRegardsTo&quot;).value + &quot;-&quot; + getField(&quot;Classification&quot;).value + &quot;-&quot; + getField(&quot;IrType&quot;).value + &quot;-&quot; +
  getField(&quot;Initial&quot;).value + &quot;-&quot; + getField(&quot;SpecialRqstProgram&quot;).value + &quot;-&quot; + getField(&quot;SpecialRequestType&quot;).value + &quot;-&quot; + getField(&quot;ReportCounty&quot;).value + &quot;-&quot; +
  getField(&quot;CompanionReports&quot;).value + &quot;-&quot; +
  getField(&quot;SensitiveCase&quot;).value +
  &quot;.pdf&quot;;
   
  // add folder name
  myFileName = &quot;/S/swi/downtime/&quot; + myFileName;
  myTrustedSpecialTaskFunc(this, myFileName);
  </code></pre>