【问题标题】:Is there a way to specify which form to use as onFormSubmit trigger when multiple forms linked to one sheet?当多个表单链接到一个工作表时,有没有办法指定使用哪个表单作为 onFormSubmit 触发器?
【发布时间】:2020-09-06 19:45:08
【问题描述】:

我目前有两个完全不同的表单,提供两个不同的函数链接到同一个电子表格(它们必须是,因为我使用两者的数据)。
我希望能够区分被触发的函数,一个名为emailQuote() 的函数例如在提交其中一个表单时,但是如果提交了另一个表单,我想触发我已经拥有的scanForQuoters() 函数,请问有什么办法吗?

我只是使用带有脚本工具的 Google App Script 来创建我自己的函数,并且可以在多个参数上触发它们,例如 onEditonFormSubmit。它能够使用 onFormSubmit 并区分提交哪个表单,这是我所关心的。

【问题讨论】:

  • 只有一个 onformSubmit 触发器。您可以使用 range.getSheet() 来确定正在写入的工作表和从中推断出正在提交的表单。

标签: javascript google-apps-script google-sheets triggers


【解决方案1】:

不,没有,但您可以根据目标工作表添加条件。以下示例使用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
  }
}

资源

【讨论】:

    【解决方案2】:

    链接到刚刚得到答案的Sheet的Form可以如下检索。

    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
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2019-11-21
      • 2019-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多