Google sheets script that sends a notification upon form submission if data is recorded in a specific column

不想你离开。 提交于 2020-01-07 05:26:06

问题


I'm trying to create a script for new google sheets that sends a notification if a form is submitted and contains data in a specific column.

In this example, if the question that populates data in column E is answered in the form, I would like an email notification with a link to the spreadsheet.

In the below script, if I set the trigger to on edit it will work if column E is edited. I cannot get it to work with on form submit, however. Can anyone help with fixing this script to work on edit?

Thanks!

function sendNotification() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Form Responses");
  var cell = ss.getActiveCell().getA1Notation();
  var row = sheet.getActiveRange().getRow();
  var cellvalue = ss.getActiveCell().getValue().toString();
  var recipients = "email@email.com";
  var subject = 'subject';
  var body = 'body';

  if (cell.indexOf('E')!=-1) {
    MailApp.sendEmail(recipients, subject, body);
  }
}

回答1:


when your script runs on a form submission trigger , there is no such thing as active cell, the form data is inserted in the last row of the sheet. You only have to look at this last row and check the right column (getLastRow() and column 5 for "E").



来源:https://stackoverflow.com/questions/24374737/google-sheets-script-that-sends-a-notification-upon-form-submission-if-data-is-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!