如何解决当多个表单链接到一张工作表时,是否可以指定将哪种表单用作onFormSubmit触发器?
我目前有两种完全不同的表格,提供了链接到同一电子表格的两种不同功能(这是因为我使用了两者的数据)。
我希望能够区分被触发的函数,例如,其中一个表单提交时一个名为emailQuote()
的函数,但是如果另一个表单提交了,我想触发一个scanForQuoters()
函数我已经有,请问有办法吗?
我只是使用带有脚本工具的Google App Script来创建自己的函数,并且可以在诸如onEdit
或onFormSubmit
之类的多个参数上触发它们。它能够使用onFormSubmit并区分我关注的是哪种表单提交。
解决方法
不,没有,但是您可以根据目标表添加条件。以下示例使用switch
,但您可以使用if..else或任何其他方式来处理条件表达式。
注意:e
用于表单提交事件对象。 e.range
可用于电子表格的表单提交触发器。
function respondToOnFormSubmit(e){
switch(e.range.getSheet().getName()){
case 'Sheet1':
// Stuff to be done when the submissions responses are sent to Sheet1
break;
case 'Sheet2':
// Stuff to be done when the submissions responses are sent to Sheet2
break;
default:
// do nothing
}
}
资源
,链接到刚刚得到答案的工作表的表单可以按以下方式检索。
function myFormSubmitFnc(e) {
var form,sheet,urlOfLinked;
sheet = e.range.getSheet();//Get the sheet tab that the Form answers were written to
urlOfLinked = sheet.getFormUrl();//Returns the URL for the form that sends its
//responses to this sheet,or null if this sheet has no associated form
form = FormApp.openByUrl(urlOfLinked);//The the Form that set the answers in the Sheet
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。