TypeError:无法从未定义中读取属性“ length”。 (第20行,文件“移动”)

时间:2019-05-28 07:00:51

标签: google-apps-script google-sheets

尝试在下面运行脚本时遇到以上消息。

我的目标是一旦用户从L列的下拉列表中选择了“批准”,就将“已验证”工作表中的每个新行复制到下一个工作表“处理中”。还要从Source(已验证)电子表格中删除一旦移至“处理中”

function copyrange() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('VALIDATED'); //source sheet
  var testrange = sheet.getRange('L:L'); //range to check
  var testvalue = (testrange.getValues());
  var csh = ss.getSheetByName('PROCESSING'); //destination sheet
  var data = [];
  var j =[];

  //Condition check in L:L; If true copy the same row to data array
for (i=0; i<testvalue.length;i++) {
  if ( testvalue[i] == 'Approved') {
  data.push.apply(data,sheet.getRange(i+1,1,1,25).getValues());
  //Copy matched ROW numbers to j
  j.push(i);
 }
 }
//Copy data array to destination sheet

 csh.getRange(csh.getLastRow()+1,1,data.length,data[0].length).setValues(data);

//Delete matched rows in the source sheet
  for (i=0;i<j.length;i++){
  var k = j[i]+1;
  sheet.deleteRow(k);

//Alter j to account for deleted rows
  if (!(i == j.length-1)) {
  j[i+1] = j[i+1]-i-1;
}
}
}

0 个答案:

没有答案