在 Google Sheets 脚本中,如何阻止函数执行超过 x 个,例如一天5次?
例如,我有一个触发器,每 20 分钟执行一次函数,根据函数中的条件发送一封电子邮件,但我只希望它每天最多发送此电子邮件 5 次。我该怎么做?
最佳答案
正如其他用户所建议的,您可以在 Project Properties 中存储一个值,并用它来计算脚本已执行的次数。我建议您使用条件将新属性与 5
进行比较。
Remind to convert the property returned result type to Integer, as it is an String by default, otherwise you won't be able to add 1 in each execution.
作为示例,我们可以使用 setProperty修改已经保存的值,例如:
var userProperties = PropertiesService.getUserProperties();
var newValue = +userProperties.getProperty('Execution_times') + 1;
userProperties.setProperty('Execution_times', newValue); // Updates stored value.
关于javascript - 如何阻止函数每天执行超过 x 次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60248907/