Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete a newly created document?
    primarykey
    data
    text
    <p>I am using a script to process a form as it is submitted. Part of it involves merging data from the form with a google doc and then emailing that doc as a pdf. Is there anyway to delete the doc once it has been sent?</p> <p>If it helps, here is my script:</p> <pre><code>function onFormSubmit(e) { //Get Form Values var candID = parseInt(e.values[1]); var emailAddress = e.values[2]; //Get Additional Settings var ssMaster = SpreadsheetApp.openById("0AierVcXWELCudDY2Y3J2Z1hoX3pLOXYzTW1pOVF3Wmc"); var settings_sheet = ssMaster.getSheetByName("Settings"); var candCodeLength = settings_sheet.getRange("B20").getValue(); var candCodeChars = settings_sheet.getRange("B21").getValue(); var tempDocumentID = settings_sheet.getRange("B14").getValue(); var candInfoSheet = ssMaster.getSheetByName("Candidate Information"); var candInfoLastRow = candInfoSheet.getLastRow(); var candInfoArray = candInfoSheet.getRange(2,1,candInfoLastRow,7).getValues(); //Find Corresponding Row for Form Entry for(var i=0; i&lt;candInfoArray.length; i++) { if (candInfoArray[i][3] === candID) { var row = i+2; } } var candIDRowNumber = row; //Create &amp; Record Candidate Code do { var candCode = createCandCode(candCodeLength, candCodeChars); } while(checkCandCode(candInfoArray, candCode) === true); candInfoSheet.getRange(row,6,1,1).setValue(candCode); candInfoSheet.getRange(row,7,1,1).setValue(emailAddress); //Create PDF var docid = DocsList.getFileById(tempDocumentID).makeCopy("Character Reference Instructions").getId(); var doc = DocumentApp.openById(docid); Logger.log(candInfoArray); Logger.log(row); var firstName = candInfoArray[(row-2)][1]; var lastName = candInfoArray[(row-2)][0]; var body = doc.getActiveSection(); body.replaceText("&lt;&lt;first&gt;&gt;", firstName); body.replaceText("&lt;&lt;last&gt;&gt;", lastName); body.replaceText("&lt;&lt;code&gt;&gt;", candCode); doc.saveAndClose(); //Send Email var message = "You have successfully completed the NHS Registration form.\n\n Your Candidate Code (different from your Candidate ID) is \"" + candCode + "\" and should be given to your character reference so that they can fill out your character reference form.\n\n If you have any questions, please email Ann Perham at ann_perham@needham.k12.ma.us." ; var subject = "NHS Registration Confirmation &amp; Character Reference Instructions"; var advancedArgs = {name: "Ann Perham", replyTo: "ann_perham@needham.k12.ma.us", attachments: doc.getAs("application/pdf")}; MailApp.sendEmail(emailAddress, subject, message, advancedArgs); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload