我正在使用脚本来处理提交的表单。其中一部分涉及将表单中的数据与google doc合并,然后通过电子邮件将该文档作为pdf发送。一旦发送了文件,有没有删除文件?
如果有帮助,这是我的脚本:
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<candInfoArray.length; i++) {
if (candInfoArray[i][3] === candID) {
var row = i+2;
}
}
var candIDRowNumber = row;
//Create & 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("<<first>>", firstName);
body.replaceText("<<last>>", lastName);
body.replaceText("<<code>>", 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 & 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);
}