1 回答
TA贡献1836条经验 获得超13个赞
一个快速的解决方案是添加一个try/catch。本质上,当MailApp.sendEmail失败时,脚本将从下一次迭代继续,直到到达data.length.
像这样包装包含MailApp.sendEmail函数的 if 语句:
function EmailTeamonFormSubmit() {
var sheet= SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1");
var startRow = 2;
var numRows = sheet.getLastRow()-1; // Number of rows to process
var lastColumn = sheet.getLastColumn(); // Last column
var dataRange = sheet.getRange(startRow, 1, numRows, lastColumn) // get the data range of the active sheet
var data = dataRange.getValues(); // get values for each row in the range
//////////////////////////////////////////////
//create a for loop; define variables based on increasing count, starting from zero
for (var i = 0; i < data.length; i++) {
var row = data[i];
var emailSubmitter = row[1];
var submitter = row[5];
var emailStakeholder = row[11];
var stakeholder = row[10];
var jobName = row[12];
var emailSentStatus = row[49]
var BusinessPartneremail = row[47]
var BusninessPartnername = row[48]
var subject = 'New Submission: '+jobName;
var uniqueID = row[46]
var Responses = row[45] //copy of the entire form response
//message to the team
var message = "Hello, "+
BusninessPartnername+ ", " +stakeholder+
""+
", A new submission was sent by " +submitter+ ". The Unique ID is: " +uniqueID+ ". The responses are below."
+Responses;
//send emails only if Status and email Status criteria are met
try{
if (emailSentStatus !== "Team email Sent"){
MailApp.sendEmail(emailSubmitter+", "+emailStakeholder+", "+BusinessPartneremail, subject, message,{noReply: true}); //write email and send
sheet.getRange(startRow + i, lastColumn).setValue("Team email Sent");// write email sent when done
SpreadsheetApp.flush(); //refresh spreadsheet
}
} // try
catch(e) {continue;}
}
}
添加回答
举报