提交后立即编辑表单回复 [英] Edit Form Responses as soon as it is submitted

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

问题描述

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

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.

我知道它涉及到类似 ScriptApp.newTrigger( edit_response) .forForm(form).onFormSubmit()。create(); 其中, form = FormApp.getActiveForm() edit_response 是接收事件 e 的函数。但是我似乎找不到能够修改表单响应的方法...

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...

推荐答案

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

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. You can also set a spreadsheet as the response destination. In that case, the Form answers will be saved to both the Form and a spreadsheet. You can not intercept the data before it's written into the Form. But you can change it immediately after it's written.

用作On Form Submit触发器的函数可以接收带有Form数据的JavaScript对象。用于事件对象的变量名称通常是字母 e,因为字母 e是单词 Event中的第一个字符。但是变量名可以是任何东西。

The function that serves as the On Form Submit trigger can receive a JavaScript object with Form data. The variable name used for the event object is often the letter "e", because the letter "e" is the first character in the word "Event." But the variable name can 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;

应用脚本文档-表单提交事件

有一个FormResponse类:

There is a FormResponse class:

应用脚本文档-FormResponse

但是它不能在Form中编辑现有的Form响应。

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

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

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