我认为我的问题出在e.values
我正在使用的('keyXXXXX', XXXXX);
。
我使用的原始代码是我从TJ Houston网站借来的东西。我正在将它用于申请流程。我按照使用
的过程编写了代码var last_name = e.values [1]
并将其与
匹配copyBody.replaceText('keyLastName', last_name);
它适用于大多数条目,但在
上失败var emergency_phone = e.values[23];
与
匹配copyBody.replaceText('keyEmergencyContactPhone', emergency_phone);
在那个表格和代码上,我有超过100行的Var和CopyBody匹配。我创建了一个更简单的测试,一旦你到了cphone就会失败。
// LAC Employement Applicaiton Script based on TJ Houston tjhouston.com (tj@tjhouston.com)
// LAC Employment Application
// Get template from Google Docs and name it
var docTemplate = "1Vb0P03a6qPfJOvo_bP_3zUM159XP18c3tfBL62L_mIs"; // *** replace with your template ID ***
var docName = "Applicaiton Review";
// When Form Gets submitted
function onFormSubmit(e) {
//Get information from form and set as variables
var email_address = "jreach@gmail.com";
var last_name = e.values[1];
var first_name = e.values[2];
var middle_name = e.values[3];
var current_address = e.values[4];
var ccity = e.values[5];
var cstate = e.values[6];
var czip = e.values[7];
var years = e.values[8];
var home_phone = e.values[9];
var cphone = e.values[10];
var email = e.values[11];
var emergency_contact = e.values[12];
var ephone = e.values[13];
// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DriveApp.getFileById(docTemplate)
.makeCopy(docName+' for '+last_name)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document’s body section
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,in our google doc template
copyBody.replaceText('key1', last_name);
copyBody.replaceText('key2', first_name);
copyBody.replaceText('key3', middle_name);
copyBody.replaceText('key4', current_address);
copyBody.replaceText('key5', ccity);
copyBody.replaceText('key6', cstate);
copyBody.replaceText('key7', czip);
copyBody.replaceText('key8', years);
copyBody.replaceText('key8', home_phone);
copyBody.replaceText('key9', cphone);
copyBody.replaceText('key10', email);
copyBody.replaceText('key11', emergency_contact);
copyBody.replaceText('key12', ephone);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
var subject = "Applicaiton Review";
var body = "You have received an application from " + last_name + "";
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf});
// Delete temp file
DriveApp.getFileById(copyId).setTrashed(true);
}
答案 0 :(得分:0)
当替换文档中的多个键时,键是必须唯一的。就个人而言,我用#符号括起所有键,这些符号对我有用,例如#key1#不会与#key10#
混淆