在提交Google表单上找不到具有给定ID的项目 [英] No item with the given ID can be found onSubmit Google Form

查看:49
本文介绍了在提交Google表单上找不到具有给定ID的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个在Google表单上运行onSubmit的脚本.它应将图像的ID上传到表单,将图像作为Blob获取,然后将其转发给一些电子邮件地址.问题是,有时(约十分之一),脚本会给出以下错误:

I created a script that runs onSubmit on a Google Form. It should get the ID of the image uploaded to the form, get the Image as Blob and then forward it to some email adress. The thing is, is that sometimes (about 1 in 10), the script gives the following error:

例外:找不到具有给定ID的项目,或者您找不到 有权访问它. 在on_Submit(代码:6:24)

Exception: No item with the given ID could be found, or you do not have permission to access it. at on_Submit(Code:6:24)

我认为这与Google将文件上传/移动到云端硬盘所需的时间有关,所以我设置了一个超时时间.该错误仍会出现,但出现的频率要少一些.有人知道这可能会出错吗?

I figured it would have to do with the time it takes Google to Upload/Move the file into Drive, so I set a timeout to give it some time. The error still appears, a little less frequent. Does anyone understand where this could go wrong?

代码:

function on_Submit(e) {
  Utilities.sleep(30 * 1000)
  var res  = e.response
  var image_id = res.getItemResponses()[0].getResponse()

  var image = DriveApp.getFileById(image_id).getBlob()}

on_Submit(e)函数链接到手动触发器,以启用DriveApp. 谢谢

The on_Submit(e) function is linked to a manual trigger to enable the use of DriveApp. Thanks

推荐答案

一些回复原来包含多个文件上传.该问题的答案是ID数组.这是正确的代码:

Some of the responses turned out to have multiple file uploads. The response to that question was an array of ID's. Here's the correct code:

Utilities.sleep(30 * 1000)
  var res  = e.response
  var image_id = res.getItemResponses()[0].getResponse()
  console.log(image_id)
  if(Array.isArray(image_id)){
    var images = [];
    for(var i in image_id){
      var id = image_id[i]
      var image = DriveApp.getFileById(id).getBlob()
      images.push(image)
    }
    console.log(images)
    GmailApp.sendEmail(SOME_EMAIL, SUBJECT, BODY, {attachments: images})
  }
  else{
    var image = DriveApp.getFileById(image_id).getBlob()
    GmailApp.sendEmail(SOME_EMAIL, SUBJECT, BODY, {attachments: [image]})
  }

这篇关于在提交Google表单上找不到具有给定ID的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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