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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…