0

私は Google Apps Script を使い始めたばかりで、スクリプトの一部を機能させるのに苦労しています。以下のスイッチ機能を参照してください。

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); 
}

さて、これが問題です。上記のステートメントは、現在期待どおりに機能します。リストから名前を選択するたびに、関数が特定のフィールドを読み取ってデータを取得する方法がわからないため、デフォルトになります。

何か案は?

4

1 に答える 1

1

ステートメントswitchには空の式があるため、常にdefault:ケースが実行されます。それは何をテストすることになっていますか?そしてe、あなたの関数への(未使用の)引数は何ですか?

于 2012-08-18T03:10:05.747 に答える