我已使用IMPORTHTML功能将实时数据导入Google Spreadsheets。我的要求是,每当单元格的值超出特定数字时,我都需要发送一封电子邮件。我在网上找到了以下内容,
{
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Profit Ratio");
var valueToCheck = sheet.getRange("D7").getValue();
if(valueToCheck > 3) {
MailApp.sendEmail("zak*******@gmail.com", "Current Profit Ratio", "Current Profit Ratio is 1:" + valueToCheck+ " !!!");
}
}
但问题是,如果价值超过 3 ,它会每分钟发送一次电子邮件,直到它低于3.我不希望这种情况发生。我想要一封电子邮件只发送一次,如果它超过3,下一封电子邮件必须是在它下降后再次超过3。另外,我希望得到3<it<10
。我怎么做这两个?
答案 0 :(得分:0)
您可以使用属性服务来跟踪执行之间是否已经处理了当前的标准满意度。
{
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Profit Ratio");
var valueToCheck = sheet.getRange("D7").getValue();
var prop = PropertiesService.getDocumentProperties(); // Quick access to properties
if (valueToCheck > 3 // Between 3 and 10
&& valueToCheck < 10
&& !prop.getProperty("processed") { // Has not been dealt with
MailApp.sendEmail(
"zak*******@gmail.com",
"Current Profit Ratio",
"Current Profit Ratio is 1:" + valueToCheck + " !!!");
prop.setProperty("processed", true); // Switch the flag so we don't send any more emails
} else if (valueToCheck <= 3) { // You might want to add || value to check >= 10 here?
prop.setProperty("processed", false); // Set property to false so that next time the value exceeds 3 we process it again
}
}