我的Google表格中有以下代码,当每月家庭预算余额低于每月预算总额的10%时,我会通过电子邮件发送给自己,这是通过每天运行一次的时间驱动触发器进行检查的。我现在要执行的操作是每月运行一次,但每月运行一次,即11月份达到“ IF”标准(每月预算余额低于10%)时,11月份不再运行,但会在12月“重置”并在12月的每月预算低于10%时运行。仅供参考,如果有帮助,“预算”工作表中A7和A8单元格中的值将通过工作表中的公式(而不是脚本)自动更新为当月的值。
感谢您的帮助,让我知道我是否可以澄清!
function FinalBudget() {
// Fetch the current budget figure
var monthBudgetPercentRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Budget').getRange("A7");
var monthBudgetPercent = monthBudgetPercentRange.getValue();
var monthBudgetValueRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Budget').getRange("A8");
var monthBudgetValue = monthBudgetValueRange.getValue();
var doIt = true;
// Checks amount of non-fixed budget spent percentage
if (monthBudgetPercent < 0.1) {
// Sends an email when non-fixed budget spent is less than 10%, gives percent & euro amount remaining in subject line
var recipientsTO = "email1@gmail.com";
var recipientsCC = "email2@gmail.com";
var Subject = "We have "+monthBudgetPercent*100+"% / "+monthBudgetValue+" € left of our non-fixed budget remaining for this month";
var message = "Check budget sheet.";
var html = message;
MailApp.sendEmail({
to: recipientsTO,
cc: recipientsCC,
subject: Subject,
htmlBody: html
});
}
}
答案 0 :(得分:1)