我正在建立一个Google表格和表格组合,用户可以在其中向我公司中的某些部门提交请求以进行简介。根据用户在提交表单时选择的内容,收集到的所有数据将自动执行并发送到各个部门。但是,由于我刚开始学习Google应用程序脚本(目前正在我学校派我给的一家公司实习),因此我无法自动将电子邮件发送给多个收件人,而无需花费很长的代码。希望有一些我不知道的方法。
我尝试在google中查找,查看了代码列表以及表单网站(例如BenCollins)之类的其他方式。
这是我编写的当前脚本:
// automatically send email to required departments
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var QA = ss.getSheetByName("Quality Alert");
var QAdata = QA.getRange(3,1,QA.getLastRow() - 2,24).getValues();
var subject = "Quality Alert";
Logger.log(QAdata);
// Data input from "Quality Alert Form"
QAdata.forEach(function(row, i)
{
var customer = row[1] ;
var part = row[2] ;
var s = row[3] ;
var id = row[4] ;
var defect = row[5] ;
var desc = row[6] ;
var reject = row[7] ;
var ok = row[8] ;
var chemA = row[9] ;
var chemB = row[10] ;
var chemC = row[11] ;
var et = row[12] ;
var fee = row[13] ;
var fqa = row[14] ;
var inner = row[15] ;
var ipqc = row[16] ;
var legend = row[17] ;
var lpsm = row[18] ;
var mlb = row[19] ;
var photo = row[20] ;
var routing = row[21] ;
var drilling = row[22] ;
var answer = row[23] ;
//only send email if "email sent out" column is blank
if (answer == '')
{
if(chemA == '✔')
{
var recipient = "adrian.peh@sanmina.com" ;
var body = "Hi,<br><br>" +
"This is a Quality Alert.Please brief the required people and submit the Briefing Record EForm it is completed." + "<br><br>" +
"The details are stated below :<br>" +
"Customer: " + customer + "<br>" +
"Part Number: " + part + "<br>" +
"S Number: " + s + "<br>" +
"ID Number: " + id + "<br>" +
"Defect : " + defect + "<br>" +
"Description : " + desc + "<br>" +
"Reject Photos : " + reject + "<br>" +
"Okay Photos : " + ok + "<br><br>" +
"Please complete it as soon as possible." + "<br><br>" +
"Thanks." ;
GmailApp.sendEmail(recipient, subject, " ",{htmlBody: body});
}
} //Bracket for if(answer = '')
});
}
它可以发送电子邮件,但仅发送给1个收件人。共有14个不同的可能收件人(用户应选择部门)。我目前仅使用“ IF”和“ ELSE”,但它会很长而且很混乱。希望有一种更简便,更快捷的方法,例如使用“ AND”或其他代码。
这是我的第一篇文章,所以如果有任何问题,请告诉我。