我是Google Apps Scripts的新手,我在使用我的脚本部分工作时遇到了一些麻烦。请参阅下面的开关功能:
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);
}
现在,继承人。上述声明现在按预期工作。每当我从列表中选择一个名称时,它就会变为默认值,因为我无法弄清楚如何让函数读取某个字段以从中提取数据。
有什么想法吗?
答案 0 :(得分:1)
您的switch
语句有一个空表达式,因此它将始终执行default:
个案。应该测试什么?什么是e
,函数的(未使用的)参数?