表单的Google脚本:提交后立即编辑表单响应 [英] Google Script for Forms: Edit Form Responses as soon as it is submitted

查看:142
本文介绍了表单的Google脚本:提交后立即编辑表单响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个只有一个项目的Google表单:一个简短的回答项目。只要我提交表单,我想要一个脚本,以便它改变响应。例如,无论用户输入什么问题,我都希望脚本将其更改为foo。

我知道它包含类似于 ScriptApp.newTrigger(edit_response)的内容。 .forForm(form).onFormSubmit()。create(); 其中 form = FormApp.getActiveForm() edit_response 是一个接收事件 e 的函数。但我似乎无法找到一种方法,可以修改窗体响应......

解决方案

Google内部的表单响应可以使用Apps脚本编辑表单 NOT 。保存到电子表格的响应可以更改,但表单中的现有响应不能更改。您可以使用代码删除表单回复,但不能使用任何Apps脚本方法进行编辑。



您可以手动设置表单提交触发器。除非您使用代码创建新表单并自动分发,否则无需从代码创建触发器。或者让人们在表单上安装附加组件。



表单回复总是写入到表单中。将表单响应数据写入电子表格也是一种选择。在写入数据之前,您无法截获数据。但是你可以在写入之后马上改变它。



用作On Form Submit触发器的函数可以接收一个带有Form数据的JavaScript对象。用于分配给对象的变量通常是e。但它可以是任何东西。

  function myOnFormSubmitFunc(e){}; 

表单提交触发器可以位于表单,表单或两者中。表单的提交对象与表单不同。例如,使用Sheet On Form Submit对象,您可以直接获取数组值。

  var arrayOfValues = e.values ; 

Apps脚本文档 - 表单提交事件



有一个FormResponse类: p>

Apps脚本文档 - FormResponse



但它无法编辑Form中的现有Form响应。


Suppose I have a Google Forms that has only one item: a short answer item. As soon as I submit the form I would like a script so that it changes the response. For example, whatever the user enters to the question, I would like a script to change it to be "foo". The form responses Google Sheet should also show "foo" as the response.

I know it involves something like ScriptApp.newTrigger("edit_response").forForm(form).onFormSubmit().create(); where form = FormApp.getActiveForm() and edit_response is a function that takes the event e. But I can't seem to find a method that can modify form responses...

解决方案

A Form response inside of a Google Form can NOT be edited with Apps Script. A response saved to a spreadsheet can be changed, but an existing response in a Form can not be changed. A Form response can be deleted with code, but not edited with any Apps Script methods.

You can manually set up an On Form Submit trigger. There is no need to create a trigger from code unless you are doing something like creating new Forms with code, and distributing them automatically. Or having people install an Add-on to the Form.

Form responses are always written into the Form. Writing the Form response data also into a spreadsheet is an option. You can not intercept the data before it's written. But you can change it immediately after it's written.

The function that serves as the On Form Submit trigger can receive a JavaScript object with Form data. The variable used to be assigned to the object is often "e". But it can be anything.

function myOnFormSubmitFunc(e) {};

An On Form Submit trigger can be either in the Form, the Sheet, or both. The On Form Submit object for the Sheet is different than for the Form. For example, with the Sheet On Form Submit object, you can directly get an array of values.

var arrayOfValues = e.values;

Apps Script Documentation - Sheets Form Submit events

There is a FormResponse class:

Apps Script Documentation - FormResponse

But it can not edit an existing Form response in the Form.

这篇关于表单的Google脚本:提交后立即编辑表单响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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