如何从同一个onFormSubmit触发器获取多个不需要的事件块? [英] How can I be getting multiple unwanted event blocks from the same onFormSubmit Trigger?

查看:75
本文介绍了如何从同一个onFormSubmit触发器获取多个不需要的事件块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上我创建了一个一个问题表格,因为我想亲自看看事件块.但是,这个过程对我来说是出乎意料的.我的描述如下:

I created a one question form this morning because I wanted to look at the event block for myself. However, the process took an unexpected turn for me. My description follows:

我正在使用以下代码记录onFormSubmit事件:

I'm logging the onFormSubmit event with the following code:

function testFormSubmission(e) {
  var lock=LockService.getUserLock();
  try{
      if(lock.tryLock(30000)) {
      var ss=SpreadsheetApp.getActive();
      var sh=ss.getSheetByName('LogSheet');
      var tA=[Utilities.formatDate(new Date(), Session.getScriptTimeZone(),"d/M/yyyy HH:mm:ss")];
      tA=tA.concat(e.values);
      tA.splice(tA.length-1,1,e.triggerUid,e.range.rowStart,e.range.columnEnd,JSON.stringify(e.values));
      sh.appendRow(tA);
      lock.releaseLock();
    }
  }
  catch (e){throw("Couldn\'t get lock for 30 seconds");return;};
}    

我下面有两个电子表格图像:

I have two images of my spreadsheet below:

实际上e.value中只有两列,一列是日期,一列是问题的答案,即绿色"或蓝色".空白列来自以下事实:我先提出三个问题并收集电子邮件,但为了简化起见决定删除其中两个,因为我自己生成了提交.

There's actually only two columns in e.values one is the date and one is the answer to the question which is either "green" or "blue". The blank columns come from the fact that I started with three questions and collecting emails but decided to remove two of them for simplicity, since I'm generating the submissions myself.

无论如何,都不应该在columnC中没有绿色或蓝色的响应. J列只是JSON.stringify(e.values),似乎表明e中的值不正确...我认为?是/否

Anyway the responses that don't have either Green or Blue in columnC just shouldn't be there. Column J is simply JSON.stringify(e.values) and it seems to suggest that e has incorrect values in it...I think? Yes/No

这是电子表格的图像. (其中一些)

Here's an image of the Spreadsheet. (some of it)

这是表单响应1表:

这是LogSheet:

This is the LogSheet:

所以我的问题很简单,日志表中多余的附加行是从哪里来的?

So my question is simply where are the unwanted appended lines in the Log Sheet coming from?

我更新了标题问题,因为我认为我不会收到多次提交,否则我希望在Form Responses 1工作表中有多行.

I updated my title question because I don't think I'm getting multiple submissions otherwise I'd expect to have multiple lines in Form Responses 1 sheet.

对于您的信息,LogSheet中的columnH是rowStart,因此很容易找出Form Response 1中的哪一行相关.

For your information columnH in LogSheet is rowStart so it's easy to figure out what row in Form Response 1 correlates.

推荐答案

获取虚假的onFormSubmit触发器

@ J.G.指出每次提交表单,我得到的不仅仅是一个触发器.

Getting spurious onFormSubmit Triggers

As @J.G. pointed out I was getting more that one trigger from each submission of the form.

通过将e.values记录到电子表格中,我注意到我没有得到任何答案.因此,为了消除这些不必要的触发器,我只使用了以下逻辑.

I noticed by logging the e.values into a spreadsheet that I was not getting any of the answers. So to eliminate these unwanted triggers I just used the following logic.

if(e.values && !e.values[1]){return;}其中,e.values[1]是必填问题.

if(e.values && !e.values[1]){return;} where e.values[1] was a required question.

我的日志:

C列中没有值的行是不需要的触发器.

The lines with no value in column C are unwanted triggers.

这篇关于如何从同一个onFormSubmit触发器获取多个不需要的事件块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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