Google Script - 根据回复将新提交的内容移动到另一个工作表 [英] Google Script - Move new submissions to another sheet based on the responses

查看:25
本文介绍了Google Script - 根据回复将新提交的内容移动到另一个工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个脚本,该脚本将采用新的表单响应并根据提交的信息将其移动到另一个工作表.例如,假设表单有两个答案选项 A、B.电子表格有三个工作表;表单响应、表单 A、表单 B.如果有人提交表单并选择 A,我需要将该新行从表单响应"移动到表单 A".我发现其他人的脚本正是这样做的,但使用了 OnEdit 函数.当提交新的表单响应时,我无法弄清楚如何修改此脚本以使其工作.

I'm trying to create a script that will take a new form response and move it to another sheet based on the information submitted. For example, let's say the form has two answer choices A, B. The spreadsheet has three sheets; Form Responses, Sheet A, Sheet B. If someone submits the form and selects A, I need that new row to be moved from "Form Responses" to "Sheet A." I found someone else's script that does exactly this but using the OnEdit function. I cannot figure out how to modify this script to work when a new form response is submitted.

function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();

if(s.getName() == "Form Responses" && r.getColumn() == 2 && r.getValue() == "A") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Sheet A");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
  }
}

我使用了可安装的触发器并用 onFormSubmit 替换了 OnEdit 函数,但这不起作用.如果有人能帮我解决这个问题,我将不胜感激.

I used the installable triggers and replaced the OnEdit function with onFormSubmit but that doesn't work. I'd really appreciate it if anyone could help me with this.

谢谢,

推荐答案

可以通过以下方式设置触发器:然后设置它:

the triggers can be set by going to: then set it:

这篇关于Google Script - 根据回复将新提交的内容移动到另一个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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