我有一个Google表单,可以接收我们图书馆藏品的新项目请求。该电子表格有一个脚本,用于根据项目类型为四个人处理四张纸之间的数据。
这些人希望能够在各自的工作表中编辑具有每个项目状态(待处理,不可用,已接收等)的列,并在已接收的原始工作表上自动更新该编辑状态表格提交。
这是我坚持的部分(我也在脚本中标记)。我提出的逻辑是每个表单提交都有一个时间戳,因此在每次编辑时,它应该运行一个循环,该循环将编辑后的工作表上的时间戳与原始提交表上的时间戳匹配,并从那里将编辑复制到主要提交表。我不知道我在做什么,只是打了一些我觉得有意义的东西,但是当我运行它时,它甚至都没有启动for循环。
链接到表格副本:(已删除)
链接到可编辑的电子表格副本:(已删除)
$
答案 0 :(得分:2)
我修改了你的onEdit功能。现在它将在响应表中更新状态。
function onEdit() {
try {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var actSheet = ss.getActiveSheet();
var responseSheet = ss.getSheetByName("Item Request");
var actCell = actSheet.getActiveCell();
var actVal = actCell.getValue();
var actLoc = actCell.getA1Notation();
var last = actSheet.getLastRow();
var respLast = responseSheet.getLastRow();
var dataA = responseSheet.getRange(1, 1, respLast, 1).getValues(); //compiles an array of data found in column A through last row in response sheet
var dataO = actSheet.getRange(1, 1, last, 15).getValues(); //compiles an array of data found in column O through last row in active sheet
var dataP = actSheet.getRange(1, 1, last, 16).getValues(); //compiles an array of data found in column P through last row in active sheet
var tstamp1 = actSheet.getRange(actCell.getRow(), 1);
var tsVal1 = tstamp1.getValue();
//===============**** THIS IS WHERE I'M STUCK ****===============================
for (i = 0; i < dataO.length; ++i) {
if (actCell.getColumn() == 15) { //checks the array to see if the edit was made to the "O" column
//----------(checking for timestamp match and copying entry)----------------------
for (k = 1; k < dataA.length; k++) {
if (dataA[k][0].toString() == tsVal1.toString()) {
var toEdit = responseSheet.getRange(k + 1, 16);
toEdit.setValue(actVal);
}
}
} else { //if edit was not made in col "O,"checks if edit was in "P" column
for (i = 0; i < dataP.length; ++i) {
if (actCell.getColumn() == 16) { // checks the array to see if the edit was made in the "P" column
//------------(checking for timestamp match and copying entry)----------------------
for (k = 1; k < dataA.length; k++) {
if (dataA[k][0].toString() == tsVal1.toString()) {
var toEdit = responseSheet.getRange(k + 1, 17);
toEdit.setValue(actVal);
}
}
} else {
return;
}
}
}
}
} catch (e) {
Logger.log(e)
}
}