-1

当用户提交谷歌表单并选中最后的框以接收副本时,他们会获得与他们交互的表单页面的格式良好、合理简洁的电子邮件视图。如何使用 onSubmit 触发器生成相同的视图?我能够得到回应,但不是很好看。

感谢您的帮助,博

function formSubmit(event) {
  var formResponse=event.response;
//Logger.log(formResponse);
  var itemResponses = event.response.getItemResponses();
//Logger.log(itemResponses);
  var editURL=event.response.getEditResponseUrl();
//Logger.log(editURL);
  var emailSubject="***DO NOT REPLY***New Request has been submitted for "+formResponse.getRespondentEmail();
  var emailBody="***DO NOT REPLY TO THIS MESSAGE***\nPLEASE REVIEW THE FULL FORM FOR ITEMS PERTAINING TO YOUR DEPARTMENT!!!"
  var emailReplyTo="someemail@adomain.root"
  var emailaddresses="someemail@adomain.root"
  var DeploymentTeam="someemail@adomain.root"
  var StoreTeam="someemail@adomain.root"
  for (var j = 0; j < itemResponses.length; j++) {
      var itemResponse = itemResponses[j];
      var itemQuestion = itemResponse.getItem().getTitle();
      var itemAnswer = itemResponse.getResponse();
//Logger.log(itemQuestion);
//Logger.log(itemAnswer);
    //Add question and response to the body of the email. Exclude questions with no response.
    if (itemAnswer != '') {
      emailBody += "\n\n\n"+itemResponse.getItem().getTitle();
      emailBody += "\n"+itemResponse.getResponse();
    }
    //BEGIN DEPLOYMENT TEAM TASKS
    if (itemQuestion == 'What are you requesting?' && itemAnswer == 'I need servers rebuilt') {
      emailaddresses += ",";
      emailaddresses += DeploymentTeam;
    }
    if (itemQuestion == 'What are you requesting?' && itemAnswer == 'I need new software deployed') {
      emailaddresses += ",";
      emailaddresses += DeploymentTeam;
    }
    //END DEPLOYMENT TEAM TASKS
    //BEGIN STORE TEAM TASKS
    if (itemQuestion == 'Do you need any CBSs\' allocated?' && itemAnswer == 'Yes') {
      emailaddresses += ",";
      emailaddresses += StoreTeam;
    }
    if (itemQuestion == 'Do you need any COWs\' allocated?' && itemAnswer == 'Yes') {
      emailaddresses += ",";
      emailaddresses += StoreTeam;
    }
    if (itemQuestion == 'Do you need any Price Verifiers\' allocated?' && itemAnswer == 'Yes') {
      emailaddresses += ",";
      emailaddresses += StoreTeam;
    }
    if (itemQuestion == 'Do you need any Store Workstations\' allocated?' && itemAnswer == 'Yes') {
      emailaddresses += ",";
      emailaddresses += StoreTeam;
    }
    //END STORE TEAM TASKS

    //Date Validation Logic
    if (itemQuestion == 'When do you need the resource(s)?') {
      var date1q1 = itemQuestion;
      var startdate1 = itemAnswer;
    }
    if (itemQuestion == 'When will you release the resource(s)?') {
      var date1q2 = itemQuestion;
      var enddate1 = itemAnswer;
      if (enddate1 < startdate1) {
        emailaddresses = formResponse.getRespondentEmail();
        emailSubject = '**INVALID REQUEST**Your end date is before your start date';
        emailBody = 'You have entered invalid request data. You will need to submit a new request with accurate dates\nPlease click '+editURL+' to edit your start and end dates, then re-submit the form\n\n';
        emailBody += date1q1+"\n";
        emailBody += startdate1+"\n\n";
        emailBody += date1q2+"\n";
        emailBody += enddate1+"\n\n";
        j = itemResponses.length
      }
    }
    if (itemQuestion == 'Start date for Test lab store allocations') {
      var date2q1 = itemQuestion;
      var startdate2 = itemAnswer;
    }
    if (itemQuestion == 'End date for Test lab store allocations') {
      var date2q2 = itemQuestion;
      var enddate2 = itemAnswer;
      if (enddate2 < startdate2) {
        emailaddresses = formResponse.getRespondentEmail();
        emailSubject = '**INVALID REQUEST**Your end date is before your start date';
        emailBody = 'You have entered invalid request data. You will need to submit a new request with accurate dates\nPlease click '+editURL+' to edit your start and end dates, then re-submit the form\n\n';
        emailBody += date2q1+"\n";
        emailBody += startdate2+"\n\n";
        emailBody += date2q2+"\n";
        emailBody += enddate2+"\n\n";
        j = itemResponses.length
      }
    }
    if (itemQuestion == 'Start date for QA lab store allocations') {
      var date3q1 = itemQuestion;
      var startdate3 = itemAnswer;
    }
    if (itemQuestion == 'End date for QA lab store allocations') {
      var date3q2 = itemQuestion;
      var enddate3 = itemAnswer;
      if (enddate3 < startdate3) {
        emailaddresses = formResponse.getRespondentEmail();
        emailSubject = '**INVALID REQUEST**Your end date is before your start date';
        emailBody = 'You have entered invalid request data. You will need to submit a new request with accurate dates\nPlease click '+editURL+' to edit your start and end dates, then re-submit the form\n\n';
        emailBody += date3q1+"\n";
        emailBody += startdate3+"\n\n";
        emailBody += date3q2+"\n";
        emailBody += enddate3+"\n\n";
        j = itemResponses.length
      }
    }
    if (itemQuestion == 'Start date for Pre-Prod lab store allocations') {
      var date4q1 = itemQuestion;
      var startdate4 = itemAnswer;
    }
    if (itemQuestion == 'End date for Pre-Prod lab store allocations') {
      var date4q2 = itemQuestion;
      var enddate4 = itemAnswer;
      if (enddate4 < startdate4) {
        emailaddresses = formResponse.getRespondentEmail();
        emailSubject = '**INVALID REQUEST**Your end date is before your start date';
        emailBody = 'You have entered invalid request data. You will need to submit a new request with accurate dates\nPlease click '+editURL+' to edit your start and end dates, then re-submit the form\n\n';
        emailBody += date4q1+"\n";
        emailBody += startdate4+"\n\n";
        emailBody += date4q2+"\n";
        emailBody += enddate4+"\n\n";
        j = itemResponses.length
      }
    }
  }

//  MailApp.sendEmail(emailaddresses, "New Request has been submitted for "+formResponse.getRespondentEmail(), emailBody);
  MailApp.sendEmail(emailaddresses, emailSubject, emailBody, {replyTo:emailReplyTo});
 var emailQuotaRemaining = MailApp.getRemainingDailyQuota()//;
 Logger.log("Remaining email quota: " + emailQuotaRemaining);
}
4

1 回答 1

0

我建议查看 MailApp ( https://developers.google.com/apps-script/reference/mail/mail-app ) 并根据响应构建您自己的基于 HTML 的电子邮件,以便在触发问题后发送。

另外,我只想提醒您,SO 是用于询问特定于代码的问题 - 而不是对我来说这个/那个的代码。如果您遇到问题并且您也可以发布代码,它会有所帮助。

于 2013-06-18T16:13:34.547 回答