如何修改触发器,以便触发器在编辑时通过电子邮件发送,但速度却不那么快? [英] How can I modify a trigger so that it emails upon edit, but not so quickly?

查看:60
本文介绍了如何修改触发器,以便触发器在编辑时通过电子邮件发送,但速度却不那么快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,可以在提交Google表单后创建其他文件.它还为所述新文档设置了触发器,以便在文档创建后对文档进行任何编辑时,都会向人们发送电子邮件,例如

I have a script that creates additional files upon submission of a Google Form. It also sets up a trigger for said new document, so that people are emailed when any edits are made to the document after its creation, e.g.

ScriptApp.newTrigger("sendEmailOnModification")
         .forSpreadsheet(SpreadsheetApp.openById(fileId))
         .onEdit()
         .create();

逻辑全部起作用,但是...触发器非常敏感.每次,只要有人在文档中进行一次击键,就会触发.有人撰写段落时反复开除没有多大意义.比方说,在最后一次编辑后10分钟触发,就更有意义了.(或其他内容.不发送垃圾邮件的任何内容.)

The logic all works, but... the trigger is extremely sensitive. Every time someone makes a single keystroke in the document, it fires. It doesn't make a lot of sense to repeatedly fire as someone writes a paragraph; it makes more sense to, say, fire 10 minutes after the last edit. (Or something. Anything that doesn't spam emails.)

是否可以修改触发器,使其触发频率降低(我需要基于时间的触发器),或者以编程方式更改Google表格保存的频率?

Is there a way to modify the trigger so that it fires less often (I do not want a time-based trigger), or otherwise programmatically change how frequently Google Sheets saves?

作为最后的选择,我想我可以创建一个隐藏的工作表来捕获上次修改的时间,以及一个条件,如果随后的修改少于X分钟之前,则不发送电子邮件,但这有点笨拙并且没有真正的吸引力.希望我可以完全在Google脚本中完成此操作.

As a last resort, I suppose I could create a hidden sheet that captures last modified time and a condition not to send an email if subsequent modifications are less than X minutes ago, but that's kind of clunky and not really appealing. Hoping I can do it entirely in Google Scripts instead.

推荐答案

我不确定如何实现此功能以满足您的需求,但是由于您不希望使用基于时间的触发器,并且您已经在使用 onEdit(),您应该可以使用 onEdit(e) e.oldValue 来检查更改是否值得该消息.

I'm not sure how you could implement this to suit your needs,but since you don't want a time based trigger, and you are already using onEdit(), you should be able to use onEdit(e) and e.oldValue to check if the change is worth the message.

这篇关于如何修改触发器,以便触发器在编辑时通过电子邮件发送,但速度却不那么快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆