我观看了一个 youtube 视频,标题为“Google Apps EDU Fireside Chat Hangout: An Introduction to Apps Script”,其中 Eric Koleda 展示了如何从 gmail 进行“批准”。
我已经复制了代码,除了 doGet 函数(见下文)外,一切正常。该功能假设在电子表格的审批列中写“是”,然后呈现一个写有“公告已获批准”的网页。
任何帮助表示赞赏。请参阅下面的代码。
function onFormSubmit(event) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('Announcements');
var title = event.namedValues['Title'];
var description = event.namedValues['Description'];
var url = 'https://script.google.com/a/macros/domain.com/s/AKfycbxT0T7bdcZ0NGmRHoZuo5onrPol9bMNDK8W4fYWol5gS09xKXk/exec';
url += '&spreadsheetId=' + spreadsheet.getId();
url += '&row=' + sheet.getLastRow();
var message = 'New announcement submitted.\n' +
'Title: ' + title +
'\nDescription: ' + description +
'\nApprove: ' + url;
MailApp.sendEmail('emailaddress@blahblah.com', 'New Announcement', message);
}
function doGet(event) {
var spreadsheetId = event.parameter['spreadsheetId'];
var spreadsheet = SpreadsheetApp.openById(spreadsheetId);
var sheet = spreadsheet.getSheetByName('Announcements');
var row = event.parameter['row'];
sheet.getRange(row, 3).setValue('Yes');
var app = UiApp.createApplication();
var label = app.createLabel();
label.setText('The announcement was approved');
app.add(label);
return app;
}