簡體   English   中英

電子郵件通知問題

[英]Problems with email notification

我是使用Google文檔腳本編輯器的新手,所以請保持友好。 這是我到目前為止的內容:

function onEdit(e) {  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  //Get Active cell
  var mycell = ss.getActiveSelection();
  var cellcol = mycell.getColumn();
  var cellrow = mycell.getRow();

  //Define variables from sheet by column
  //Column count starts at 0, not 1.
  var timestamp = e.values[cellrow,14];
  var yourName = e.values[cellrow, 0];
  var email = e.values[cellrow, 1];
  var plot2013 = e.values[cellrow, 5];
  var plotrequest = e.values[cellrow, 6];
  var sharing = e.values[cellrow, 7];
  var totalprice = e.values[cellrow, 8];
  var paid = e.values[cellrow, 13];
  var subject = "TSF Payment Confirmation"

  //email body
  var emailBody = "Thank you for your payment submitted on " + timestamp +
    "\n\nThe details you entered were as follows: " +
    "\nYour name: " + yourName +
    "\nYour plot #: " + plot2013 +
    "\nNumber plots requested: " + plotrequest +
    "\nSharing plot with: " + sharing +
    "\nTotal payment: " + totalprice;

  //html version of email body
  var htmlBody = "Thank you for your payment submitted on <i>" + timestamp +
    "</i><br/>&nbsp;<br/>The details you entered were as follows: " +
    "<br/><font color=\"red\">Your Name:</font> " + yourName +
    "<br/>Your Email: " + plot2013;
    "<br/>Plots requested: " + plotrequest;
    "<br/>Sharing plot with: " + sharing +
    "<br/>Total payment: " + totalprice;

  //sends email if cell contents are 'yes'
  if (e.values[13,cellrow] == "yes") {
    //Sends email
    MailApp.sendEmail(email, subject, emailBody);
  }
}

我希望的是,一旦用戶單擊第13列(假定其從左側的0開始計數,而不是可變數字)並鍵入“是”,它將通過電子郵件從該用戶行發送信息。

我收到一條錯誤消息,說:

var時間戳記未定義

我是從以下示例中獲得的: http//alamoxie.com/blog/tech-tips/sending-confirmation-emails-google-docs-form/

您正試圖以一種沒有意義(或無法正常工作)的方式引用這些單元格。 請嘗試以下經過測試/工作的代碼:

function onEdit(e) {  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  // Ensure the event was triggered by typing "yes" in the appropriate column
  if(e.range.getColumn() == 14 && e.value.toUpperCase() == "YES"){
    // Get the corresponding row
    var row = sheet.getRange(e.range.getRow(), 1, 1, sheet.getLastColumn()).getValues()[0];

    // Define variable from row by column
    var timestamp = row[14];
    var yourName = row[0];
    var email = row[1];
    var plot2013 = row[5];
    var plotrequest = row[6];
    var sharing = row[7];
    var totalprice = row[8];
    var paid = row[13];
    var subject = "TSF Payment Confirmation"

    // Construct the email body
    var emailBody = "Thank you for your payment submitted on " + timestamp +
      "\n\nThe details you entered were as follows: " +
      "\nYour name: " + yourName +
      "\nYour plot #: " + plot2013 +
      "\nNumber plots requested: " + plotrequest +
      "\nSharing plot with: " + sharing +
      "\nTotal payment: " + totalprice;

    // Construct an HTML version of the email body
    var htmlBody = "Thank you for your payment submitted on <i>" + timestamp +
      "</i><br/>&nbsp;<br/>The details you entered were as follows: " +
      "<br/><font color=\"red\">Your Name:</font> " + yourName +
      "<br/>Your Email: " + plot2013;
      "<br/>Plots requested: " + plotrequest;
      "<br/>Sharing plot with: " + sharing +
      "<br/>Total payment: " + totalprice;

    // Send email
    MailApp.sendEmail(email, subject, emailBody);
  }
}

注意,我將所有內容放入條件語句中。 如果第N列中的單元格未更改為“是”,則嘗試解析所有數據是沒有意義的。 之后,我立即從已編輯的行中檢索所有值,並用結果填充所有變量。 其余內容與您編寫的內容幾乎相同。

祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM