我对 Google Apps 脚本很陌生,我在让我的脚本的一部分工作时遇到了一些麻烦。看下面的开关功能:
function sendFormByEmail(e) {
var emailSubject = "Request for Sample";
// Set with your email address or a comma-separated list of email addresses.
var yourEmail = "staticemailgoeshere";
// Set with your spreadsheet's key, found in the URL when viewing your spreadsheet.
var docKey = "SHEETKEYHERE";
// If you want the script to auto send to all of the spreadsheet's editors, set this value as 1.
// Otherwise set to 0 and it will send to the yourEmail values.
var useEditors = 0;
switch () {
case "Name 1":
yourEmail = "emailaddress";
break;
case "name 2":
yourEmail = "emailaddress";
break;
case "Name 3":
yourEmail = "emailaddress";
break;
case "Name 4":
yourEmail = "emailaddress";
break;
default:
yourEmail = "defaultemail"
}
if (useEditors) {
var editors = DocsList.getFileById(docKey).getEditors();
if (editors) {
var notify = editors.join(',');
} else var notify = yourEmail;
} else {
var notify = yourEmail;
}
// The variable e holds all the submission values in an array.
// Loop through the array and append values to the body.
var s = SpreadsheetApp.getActive().getSheetByName("Sheet1");
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
for(var i in headers) {
message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + '\n\n';
}
MailApp.sendEmail(notify, emailSubject, message);
}
现在,事情就是这样。上面的语句现在按预期工作。每次我从列表中选择一个名称时,它都会默认,因为我无法弄清楚如何让函数读取某个字段以从中提取数据。
有任何想法吗?