Google Spreadsheet代码段不起作用

时间:2018-06-06 09:42:51

标签: javascript email spreadsheet code-snippets

我有一个电子表格(链接如下)。当用户提交谷歌表格时,数据将被插入其中。我想将平均“第8列”发送到电子邮件“第2列”我创建了两个文件,一个是“触发器”(检查更改),另一个包含将发送电子邮件的功能。

当用户插入记录时,触发器将调用该函数。在该功能之后,检查“email_sent”状态并发送平均值以记录电子邮件。

我没有通过电子邮件收到平均值请帮帮我。

https://docs.google.com/spreadsheets/d/1PzE_OmhhbM0IG-dtUV5LZb7PPrXovaPZStWNYGUMCVg/edit?usp=sharing

Trigger.gs文件

function initializeTrigger(){ // run this only once to create a trigger if necessary
  var sheet = SpreadsheetApp.getActive();
 ScriptApp.newTrigger("sendingEmail")
   .forSpreadsheet(sheet)
   .onChange()
   .create();
}
function.gs文件

/* please edit this function for your message format */
function buildMessageRow(row) {
  return (
    'You average marks are :' + row[9] 
    
  )};



function sendingEmail() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const allValues = sheet.getDataRange().getValues();
  const columnForSentMarker = 8; /*  sent marker column */
  const markerForSentEmail = 'email_sent';
  var messages = '';
  allValues.forEach(function (row, index) {
    if (index === 0) return; /* skip 1st row for labels */
    if (row[columnForSentMarker - 1] === markerForSentEmail) 
      return;
   message += buildMessageRow(row);
    sheet.getRange(index + 1, columnForSentMarker).setValue(markerForSentEmail);
  });
  /* Logger.log(messages);  TODO: change logging to email sending */
  
  
  var emailAddress = row[1];  // First column
 // var message = row[8];       // Second column
  var subject = "Your Average of Assesment";
  
  MailApp.sendEmail(emailAddress, subject, message);
  
}

0 个答案:

没有答案