寻找有关如何更好地写这个的建议。来源是Google表格。我有另外几个IF ELSE语句,所以希望合并代码。
我还想要另一个条件,如果employed == "NO" && school == "NO"
和邮政编码与列出的邮件不匹配,它会发送一封单独的电子邮件。
代码被截断以最好地解决特定问题。
if (status == "" && postcode == "4518" || postcode == "4519" || postcode == "4550" || postcode == "4551" || postcode == "4552" || postcode == "4575" && employed == "NO" && school == "NO") {
MailApp.sendEmail(
// to email 1
}
);
}
else if (status == "" && postcode == "4556" || postcode == "4557" || postcode == "4558" || postcode == "4564" && employed == "NO" && school == "NO") {
MailApp.sendEmail(
// to email 2
}
);
}
}
我可能有第二个数据集,其中有两列,邮政编码和电子邮件地址。如果找到邮政编码MATCH,则会发送到B列中列出的电子邮件地址。如果未找到匹配项,则employed == "NO" && school == "NO"
会发送回复电子邮件。不知道怎么写,也不知道如何开始研究。
答案 0 :(得分:3)
所以,有两件事-
indexOf
条件下function myFunction() {
var postcode = '4558';
var status = 'whatever';
var employed = 'foo';
var school = 'bar';
var postcode1 = ["4518","4519","4550","4551","4552","4575"];
var postcode2 = ["4556","4557","4558","4564"];
if (status == "" && employed == "NO" && school == "NO") {
if(postcode1.indexOf(postcode) !== -1) {
Logger.log("email 1");
} else if (postcode2.indexOf(postcode) !== -1) {
Logger.log("email 2");
}
}
}
(请参阅this)您可以相应地重构代码,如下所示-
postcode1
在这里,postcode2
和{{1}}只是2个不同的数据数组,也可以使用常规电子表格服务来使用。
希望这会有所帮助。