我创建了一个写入电子表格的表单。 Apps脚本在onSubmit上运行并查找新数据并向管理员发送电子邮件 经理收到了一封带有“批准”按钮的电子邮件。
我无法将批准者回复发布回电子表格。
当审批者选择按钮时,显示消息“找不到脚本功能: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));
}
答案 0 :(得分:0)
action="xxxx"
中的网址应该是“发布”对话框中提供的网址。它将以/exec
结束。您需要publish your script作为网络应用,它会为您提供一个网址,并确保在那里调用您的doPost()
方法。