0

我创建了一个写入电子表格的表单。Apps 脚本在提交时运行并查找新数据并向经理发送电子邮件。经理收到带有批准按钮的电子邮件。

我无法将批准者的回复发布回电子表格。

当审批者选择按钮时,消息“找不到脚本功能:doPost”

var COLUMN_STATE = 4; //the number is the column # + 1  6 = column G (7th column)
var COLUMN_APROVE = 5
var STATE_APPROVED = "APPROVED";
var STATE_REJECTED = "REJECTED";
var STATE_MANAGER_EMAIL = "MANAGER_EMAIL";

var REQUEST_SPREADSHEET_ID = "0AkbHPyoRSG2DdDJpaWd1bGEzb19HY2pjVHdiQUhxNUE";

// Main tutorial function: For each row
//   - if it has recently been APPROVED or REJECTED by a manager, email the results to 

function onRequest() {
  // This is the Request Spreadsheet
  var ss = SpreadsheetApp.openById(REQUEST_SPREADSHEET_ID);
  var sheet = ss.getSheets()[0];

  // Fetch all the data from the Request Spreadsheet
  // getRowsData was reused from Reading Spreadsheet Data using JavaScript Objects 
  var data = getRowsData(sheet);

  // For every Request
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    row.rowNumber = i + 2;
    if (!row.state) {
      // This is a new Request
      // Email the manager to request for approval.
      sendReportToManager(row);// Update the state of the Request
      sheet.getRange(row.rowNumber, COLUMN_STATE).setValue(row.state);
    } 
   }
  }


// Sends an email to a manager to request approval 
function sendReportToManager(row) {
  var subject = "ID#" + " " + row.rowNumber + " "+"Request for Time Off"
  var message ='<form action="xxxx" method="Post">' +
      "<P>" + "Request Id: " + row.rowNumber + "</P>"+ 
      "<P>" + row.username + " has requested your approval for Time Off." + "</P>"+ 
      '<input type="hidden" name="row" value="' + row.rowNumber +'" /> ' +
      '<input type="submit" value="Submit" />' +
      '</form>';
      //(Logger.log(row));
  MailApp.sendEmail(row.supervisorsEmail,subject, "", {htmlBody: message});
  row.state = STATE_MANAGER_EMAIL;
}

function doPost(e) {
  var template = HtmlService.createTemplateFromFile('Thanks.html');
  template.name = e.parameter.name;
  template.comment = e.parameter.comment;
  template.screenshot = e.parameter.screenshot;
  return template.evaluate();
  (Logger.log(e));
}
4

1 回答 1

0

中的 URLaction="xxxx"应该是“发布”对话框中提供的 URL。它将以/exec. 您需要将脚本发布为 web 应用程序,这将为您提供一个 URL,并确保在doPost()那里调用您的方法。

于 2013-08-29T12:34:16.447 回答