如果在Google表单中写入了某个值,则发送电子邮件 [英] Send email if certain value is written in Google Forms

查看:98
本文介绍了如果在Google表单中写入了某个值,则发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Gforms,并且需要发送电子邮件给朋友当提交的最后一个表格在J列中有一定的值时,在这种情况下:Roberto。这是我的剧本。但它似乎没有工作,当价值提交表单时,我没有收到任何电子邮件。

I am working with Gforms and I need to send an email to "A Friend" When the last form submitted has in the "J" Column a certain value, in this case: "Roberto". This is my script. But it seems not to be working, I get no email when that value is submitted in a form. I did setup the trigger to run the script when a form is submitted.

function myNotification() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ranchE = e.range.getRow();
  var Kjota = "J";
  var rangex = Kjota + ranchE;
  var value = ss.getSheetByName("Respuestas de formulario").getRange(rangex).getValue();
  var email = "heregoes@myemail.com";
  if( value == "Roberto" ) {
      MailApp.sendEmail(email, "Test", "Yes is Roberto");
  }
}


推荐答案

访问发送到你的函数的事件信息,你需要包含 e 作为参数。请参阅了解事件,以了解传递给您的触发器功能的信息。

To access the event information that's sent to your function, you need to include e as a parameter. See Understanding Events to learn about the information that is passed to your trigger function.

例如, e.values 是由触发该函数的表单提交的值数组。您不需要阅读电子表格 - 信息将免费提供给您。

For example, e.values is an array of values that were submitted by the form that triggered the function. You don't need to read the spreadsheet - the information is handed to you for free.

由于它是一个数组,因此 e.values

Since it's an array, e.values starts numbering from 0. So to access column J, you need element 9. (J is the 10th column on the spreadsheet.)

如果我们想要从字母计算列数,我们可以这样做:

If we wanted to calculate column numbers from letters, we could do it this way:

var Kjota = "J";
var colIndex = Kjota.charCodeAt(0) - 'A'.charCodeAt(0);  // colIndex = 9

还有一件事 - 如果它是您的脚本,并且您希望将电子邮件发送给你可以很容易地使用会话服务来获得你自己的电子邮件。这使得您的脚本也更容易分享。

One more thing - if it's your script, and you want the email sent to you, it's easy to get your own email using the Session service. That makes your script easier to share, too.

所以,这里就是你需要的全部:

So, here's all you need:

function myNotification(e) {
  if( e.values[9] == "Roberto" ) {
      var email = Session.getUser().getEmail();
      MailApp.sendEmail(email, "Test", "Yes is Roberto");
  }
}

这篇关于如果在Google表单中写入了某个值,则发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆