问题描述
我已经在论坛中搜索了几次,但无法为我的问题提供答案。
I've searched through the forums a few times and I wasn't able to suss out an answer to my issue.
我正在使用Google表格来跟踪团队的项目进度。我目前有5个用户,每个用户都有自己的标签,另外还有3个其他标签是动态的,但对于除我之外的任何用户来说都是相当容易的选择。
I'm using Google Sheets to track project progress for my team. I currently have 5 users, each with their own tab, plus three additional tabs that are intended to be dynamic though fairly hands-off for any user except myself.
为了使此跟踪器易于使用,我实现了一个onEdit脚本,可将任何标记为已完成的项目从用户选项卡移至已完成
In order to make this tracker easy to use, I've implemented an onEdit script to move any project that's marked "completed" from the user's tab over to the "completed" tab automatically.
该脚本在最初测试过几次后仍能正常工作,但现在遇到了此错误:
The script worked fine the first few times I tested it out, but now I'm encountering this error:
我不确定脚本为什么找不到源,所以我不确定我需要修复我的代码。
I'm not entirely sure why the script is unable to find the source, so I'm not sure what I need to fix in my code.
function onEdit(event) {
// assumes source data in sheets named Laura, Jedsen, Erin, Tim, Hunter
// target sheet of move to named Completed
// test column with completed is col 11 or K
// must create new script when adding in a new writer
var ss = SpreadsheetApp.getActiveSheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Laura" && r.getColumn() == 11 && r.getValue() == "Completed") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
if(s.getName() == "Jedsen" && r.getColumn() == 11 && r.getValue() == "Completed") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
if(s.getName() == "Erin" && r.getColumn() == 11 && r.getValue() == "Completed") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
if(s.getName() == "Hunter" && r.getColumn() == 11 && r.getValue() == "Completed") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
if(s.getName() == "Tim" && r.getColumn() == 11 && r.getValue() == "Completed") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
推荐答案
外观您正在通过脚本编辑器运行该函数。在这种情况下,事件
是不确定的。要了解有关如何测试触发功能的信息,请参见
Looks that you are running the function from the Script Editor. In this case, event
is undefined. To learn about how to test a trigger function see How can I test a trigger function in GAS?
这篇关于TypeError:无法读取属性“ source”来自未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!