Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

javascript - GoogleSheets script to sendEmail upon form submission, how should I handle a formatting error for a blank cell?

Simple call logger/lead sheet generator using Google Forms and a script to send out the lead upon submission. I'm getting a format error when the user does not input a date into the field. I don't want to require an appt. time/date in the form. Here is my code:

function sendEmails() {

  //gets list of 
  var leadss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("LatestLeadSheet");
  var leadList = leadss.getRange(3, 1, leadss.getLastRow() - 2, leadss.getLastColumn()).getValues();
  var timeZone = Session.getScriptTimeZone();


  var today = Utilities.formatDate(new Date(), timeZone, "MM/dd/yyyy"); //Today's date for email subject line
  var fullMessage = ""; //clears fullMessage variable

  // Creates body of email. Looping through each array from LatestLeadSheet tab 
  for (var j = 0; j < leadList.length; j++) {

    var message = "Client Name: " + leadList[j][1] + "
" +
      "Client Phone: " + leadList[j][3] + "
" +
      "Client Email: " + leadList[j][8] + "
" +
      "Interested in: " + leadList[j][5] + "
" +
      "Quoted rate of: " + leadList[j][6] + "
" +
      "Notes: " + leadList[j][7] + "
" +
      "Appointment Set for: " + Utilities.formatDate(leadList[j][10], timeZone, "HH:mm  MM/dd/yyyy") + "
"
      //+"At: "+Utilities.formatDate(leadList[j][11],timeZone,"h:mm a") + "

"
      +
      "Referral Source: " + leadList[j][2] + "
" +
      "Other Info: " + leadList[j][4] + "
" +
      "Documents were sent (Y/N): " + leadList[j][9] + "
" +
      "Call was taken at: " + Utilities.formatDate(leadList[j][0], timeZone, "HH:mm  MM/dd/yyyy") + "
" +
      "Call was logged by: " + leadList[j][12] + "



";
    var fullMessage = fullMessage + message;
  }

  //Sends email to each recipient listed on SalesTeam tab  
  var subject = "DMS Call Sheet from: " + today;
  var emailss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SalesTeam");
  var lr = emailss.getLastRow();

  for (var i = 2; i <= lr; i++) {

    var currentEmail = emailss.getRange(i, 2).getValue();
    MailApp.sendEmail(currentEmail, subject, "Please follow up with the following potential clients: 

" + fullMessage)
  }

}
question from:https://stackoverflow.com/questions/65944440/googlesheets-script-to-sendemail-upon-form-submission-how-should-i-handle-a-for

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...