简体   繁体   English

在 Email 消息中获取 Google Forms 响应

[英]Get Google Forms Responses in an Email Message

I'm writing to you because I'm facing a problem with an automatic email script based on Google Form submission (or new GSheet entry when GForm is sent).我写信给您是因为我遇到了基于 Google 表单提交(或发送 GForm 时的新 GSheet 条目)的自动 email 脚本的问题。 Process in short:流程简述:

I have a Google Form ( here's similar one ) that is linked to Data Studio and Power BI Dashboards.我有一个链接到 Data Studio 和 Power BI 仪表板的 Google 表单( 这里有一个类似的表单)。 Based on data that goes into spreadsheets, the forms are automatically pre-filled using calculated fields in dashes (Date, ActionID, Code, ID, Location etc.) and data goes to Dash-linked spreadsheet [Example of what it might look like] .根据进入电子表格的数据,forms 会自动使用破折号中的计算字段(日期、ActionID、代码、ID、位置等)进行预填充,并且数据会进入破折号链接的电子表格[可能看起来像的示例] . The thing is that in case of errors found during inspections, the copy of the form/email should be also sent to Employee (optionally, the person that is superior to them, so that both know the details, not only the auditor who fills-in the form – just option).问题是,如果在检查过程中发现错误,表格/电子邮件的副本也应发送给员工(可选,比他们高的人,以便双方都知道详细信息,而不仅仅是填写的审计员-在表格中 – 只是选项)。 I can't use any available Add-ons for GForms due to sensitive nature of data.由于数据的敏感性,我无法使用任何可用的 GForms 附加组件。 Auditors don't have edit access to Forms/Dashes, and sending all information via email would take too long.审计员没有对 Forms/Dashes 的编辑权限,并且通过 email 发送所有信息会花费太长时间。 I also created a test Google Form to demonstrate what it looks like .我还创建了一个测试 Google 表单来演示它的外观 All in all, What I'm looking for is a dynamic script that will also grab company email of the employee (supervisor is optional), and when auditor submits the form, the email/copy of the form also goes to those mentioned aboce.总而言之,我正在寻找的是一个动态脚本,它还将获取员工的公司 email(主管是可选的),当审计员提交表格时,表格的电子邮件/副本也会发送到上述人员。 I couldn't find anything GForms related.我找不到任何与 GForms 相关的内容。

I used a similar script before, but don't think it was based on new rows added to spreadsheets [Example] .我以前使用过类似的脚本,但不要认为它是基于添加到电子表格[Example]的新行。 If it's not possible to achieve something like this, even spreadsheet entry form/email would be really greatly appreciated (email based on "EmployeeEmail" from form + selected columns included, as marked in sheet), although I'm afraid of things going wrong in a file with lots of rows.如果不可能实现这样的目标,即使是电子表格输入表格/电子邮件也会非常感激(基于表格中的“EmployeeEmail”的电子邮件+包括选定的列,如表中所示),尽管我担心事情会出错在一个有很多行的文件中。 I tried to find something similar and discovered 2 scripts, but I don't know how to make them dynamic: The first one below just sends messages to emails from a given range and it's static (range).我试图找到类似的东西并发现了 2 个脚本,但我不知道如何使它们动态化:下面的第一个只是将消息发送到给定范围内的电子邮件,它是 static(范围)。

thanks, It looks good.谢谢,它看起来不错。 but I have 2 issues.但我有两个问题。 Edit:, it always needs that dummy email ('xxx@xxx.xxx'”, which means I'll (or sb else) be getting hundreds of emails. Can we somehow get rid of this line or replace it with form sender email (I can replace existing column with one with form sender email (google form add emails automatically)/those that are already in columns 2/3?编辑:它总是需要虚拟 email('xxx@xxx.xxx'”,这意味着我(或其他人)会收到数百封电子邮件。我们能否以某种方式摆脱这一行或将其替换为表单发件人 email (我可以用表单发件人 email(谷歌表单自动添加电子邮件)/那些已经在第 2/3 列中的列替换现有列?

2nd thing, how can I concatenate dummy message lines to variables: var message = row.join('\n');第二件事,如何将虚拟消息行连接到变量:var message = row.join('\n'); (currently adds values from row n) (当前添加第 n 行的值)

eg can we somehow replace text join with eg例如,我们能否以某种方式将 text join 替换为 eg

// Info from specific columns
var Date = lastRowValues[n][5]; //I don’t know how to grab last value from columns, it’s probably something like variable.getLastRow() + variable.getLastColumn() + Get values
var ID = lastRowValues[n][6];
var Code= lastRowValues[n][8];
var Action = lastRowValues[n][9];
var Location = lastRowValues[n][10];
var ErrorType = lastRowValues[n][11];

and then in message然后在留言中

// var = message = “You’ve made an error. Please find the details below.” +
“\n “ +
“\n Date of Action:  “ + Date + 
“\n ID:  “ + ID +
“\n Action Code:  “ Code +
“\n Type of Action:  “ + Action +
“\n Location:  “ + Location +
“\n Error Type:  “ + ErrorType  +

The rest, such as the title, may stay the same. rest,如标题,可以保持不变。 I realised that numbers only are hard to read.我意识到只有数字很难阅读。 Is it possible to achieve this output?有可能实现这个 output 吗? This is what it looks like now .这就是现在的样子

You can add this code in your linked spreadsheet:您可以在链接的电子表格中添加此代码:

// this function will fires automatically 
// it grabs all data from the last row and send it via email

function send_email() {
  var row = SpreadsheetApp.getActive().getDataRange().getValues().pop();
  var message = row.join('\n');
  var subject = 'test subject';
  var address = 'xxx@xxx.xxx';
  GmailApp.sendEmail(address, subject, message);

  // additional emails

  var address2 = row[2];
  GmailApp.sendEmail(address2, subject, message);

  var address3 = row[3];
  GmailApp.sendEmail(address3, subject, message);

}


// this function should be run just once to install the trigger

function install_onFormSubmitTrigger() {
  var ss = SpreadsheetApp.getActive();
  ScriptApp.newTrigger('send_email').forSpreadsheet(ss).onFormSubmit().create();
}

After you install the trigger every time your form was submitted all data from the form (= all cells from the last row on the sheet) will be sent to xxx@xxx.xxx .每次提交表单时安装触发器后,表单中的所有数据(= 工作表最后一行的所有单元格)都将发送到xxx@xxx.xxx And to two additional addresses from cells 'C' and 'D'.以及来自单元格“C”和“D”的另外两个地址。

Feel free to change the code as you need.根据需要随意更改代码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM