简体   繁体   English

从表单提交创建并通过电子邮件发送 google doc

[英]Create and email google doc from form submission

I'm trying to create a Google doc from a form submission and send the doc via email.我正在尝试从表单提交创建 Google 文档并通过电子邮件发送文档。 THe data for the doc comes from a second sheet (not the response sheet) that looks up values based on the submission (a student id that looks up student, parent, class, and teacher data placed in a 3rd sheet).文档的数据来自第二张表(不是响应表),该表根据提交(查找学生、家长、班级和教师数据的学生 id 放在第三张表中)查找值。 For some reason, the email and doc that is created and sent is the previous submission, but not the latest submission.由于某种原因,创建和发送的电子邮件和文档是以前的提交,而不是最新的提交。 My scripting knowledge is insufficient to figure this one out.我的脚本知识不足以解决这个问题。 Any help is much appreciated.任何帮助深表感谢。 My document 我的文件

function createNewGoogleDocs() {
const googleDocTemplate = DriveApp.getFileById('1Q5s3doVHDDNygeLFNLqm90x9JoVZTIFW77Xix7VckVs');
var cache = CacheService.getScriptCache();
const destinationFolder = DriveApp.getFolderById('1rE8vvX9omreAUy7gnrhxpYcfM6uK3v4r')
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data')
const rows = sheet.getRange("Data!A2:S2").getValues();
const friendlyDate = new Date(rows[4]).toLocaleDateString("dd/mm/yyyy");
const sheetR = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Responses')
rows.forEach(function(row, index){
const copy = googleDocTemplate.makeCopy(`${row[12]}, ${row[13]}` , destinationFolder)
const doc = DocumentApp.openById(copy.getId())
const body = doc.getBody();
const friendlyDate = new Date(row[4]).toDateString();
body.replaceText('{{timestamps}}', row[0]);
body.replaceText('{{emailSG}}', row[1]);
body.replaceText('{{rutalumnoa}}', row[2]);
body.replaceText('{{cOMMENTS}}', row[3]);
body.replaceText('{{fecha}}', friendlyDate);
body.replaceText('{{solicitadapor}}', row[5]);
body.replaceText('{{asistentes}}', row[6]);
body.replaceText('{{objetivo}}', row[7]);
body.replaceText('{{familia}}', row[8]);
body.replaceText('{{colegio}}', row[9]);
body.replaceText('{{conclusionyacuerdos}}', row[10]);
body.replaceText('{{sTUDENTnAME}}', row[12]);
body.replaceText('{{cLASS}}', row[13]);
body.replaceText('{{tEACHERNAME}}', row[14]);
body.replaceText('{{motherName}}', row[15]);
body.replaceText('{{fatherName}}', row[16]);
body.replaceText('{{motherRut}}', row[17]);
body.replaceText('{{fatherRut}}', row[18]);
doc.saveAndClose();
const url = doc.getUrl();
const docname = doc.getName();
const StudentName = sheet.getRange("M2").getValue();
const Class = sheet.getRange("N2").getValue();
sheet.getRange("U2").setValue(url);
const GDoc =  sheet.getRange("U2").getValue();
const emailAddress = sheet.getRange("B2").getValue();
const message = 'Entrevista: Alumno/a ' + StudentName +', Curso: ' + Class +', Archivo: ' + docname +', ' + GDoc;
const subject = 'Entrevista: ' + StudentName +', ' + Class;
MailApp.sendEmail(emailAddress, subject, message);
sheetR.deleteRow(2);
})
}

In the end the error was in the spreadsheet;最后错误出现在电子表格中; the range from the response sheet that I was using was obtained by using the Importrange method.我使用的响应表中的范围是通过使用 Importrange 方法获得的。 I changed the method to an Index and Counta method (Eg. =index(Responses!A2:K,Counta(Responses!A2:A))).我将该方法更改为 Index 和 Counta 方法(例如 =index(Responses!A2:K,Counta(Responses!A2:A)))。 This did the trick.这成功了。 No need to delete the responses in the script.无需删除脚本中的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 google apps脚本,用于在表单提交后创建更新后的单元格的新pdf文档,并通过电子邮件发送此pdf错误消息: - google apps script to create new pdf document of updated cells after form submission and email this pdf error message: 从表单提交中排除特定的电子邮件地址 - Exclude a specific email address from form submission 如何创建 Zapier 表单提交然后发送 Email - How can I create Zapier Form Submission then Send Email 使用PHP从mySQL数据库的表单提交中生成电子邮件 - Generate email from form submission from mySQL database using PHP 提交表单后发送电子邮件 - send email after form submission 表单提交到电子邮件和Mailchimp订阅 - Form submission to email and Mailchimp subscription 如何使用表单验证从前端表单提交创建woocommerce产品 - How to create a woocommerce product from frontend form submission with form validation 如何在表单提交时使用Google跟踪代码管理器存储字段中的文本 - How to store text from field with Google Tag Manager on a form submission 获取用于发送Google表单提交内容的IP - Acquiring IP from which Google Form submission was sent 从表单提交跟踪中捕获URL-Google Analytics(分析) - Capturing URL from Form Submission Tracking - Google Analytics
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM