Error Decode: TypeError: Cannot read property '2' of undefined

Error Decode: TypeError: Cannot read property '2' of undefined

我一直在努力理解我在以下脚本中哪里出了问题。该脚本的目的是在 'individual_client_sheet' 中的唯一 ID 与两个 sheet 中的行中的一个 ID 相匹配时删除一行:'clients_database' 和 'clients_sheet'。到目前为止,代码能够删除每个 sheet 中的相应行,但是错误消息“TypeError: Cannot read 属性 '2' of undefined”不断弹出,我无法理解为什么。其次,脚本不会重置 'individual_client_sheet' 中的字段,因此它似乎在删除记录后停止工作。这是脚本:

   function deleteClientRecord () {
   // Get Active Sheets
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var shClient = ss.getSheetByName ('individual_client_sheet');
    var shData = ss.getSheetByName ('clients_database');
    var shClientsList = ss.getSheetByName ('clients_sheet');

   // Obtain and verify user response 
    var ui = SpreadsheetApp.getUi();
    var response = ui.alert ('Delete', 'Are you sure you want to remove this record?', ui.ButtonSet.YES_NO);

   if (response == ui.Button.NO) {
    return;
   }

   var searchValue = shClient.getRange('AF2').getValue();
   var shDataValues = shData.getDataRange().getValues();
   var shClientsListValues = shClientsList.getDataRange().getValues();


   // Delete record from 'clients_database'
      var shDataValuesFound = false; 

      for (var i = 0; i < shDataValues.length; i++) {
      var rowValue = shDataValues[i]; 

       if (rowValue[3] == searchValue) {
        var iRow = i+1;
        shData.deleteRow(iRow);
       }
      }


  // Delete record from All CLients Sheet 
     var shClientsListValuesFound = false; 

     for (var j = 0; i < shClientsListValues.length; j++) {
     var rowValue2 = shClientsListValues[j];

     if (rowValue2[2] == searchValue) {
      var jRow = j+1;
      shClientsList.deleteRow(jRow);

 ui.alert('Record deleted for - Client #' + shClient.getRange('AF2').getValue() + '');  
  }
 }

 // Delete Fields

 // Checkboxes 
   shClient.getRange('Z10:AA13').setValue(false);
   shClient.getRange('AP5:AQ5').setValue(false);
  
  // Basic Client Info
    shClient.getRange('B5:G5').clearContent(); // Business Name
    shClient.getRange('AF2').clearContent(); // Client ID
    shClient.getRange('B10').clearContent(); // website
    shClient.getRange('B12:B13').clearContent(); // billing add         
    shClient.getRange('B15:B16').clearContent(); // postal add 
    shClient.getRange('B18').clearContent(); // primary contact 
    shClient.getRange('B20').clearContent(); // phone
    shClient.getRange('B22').clearContent(); // email
    shClient.getRange('B26').clearContent(); // additional info 1          
    shClient.getRange('B28').clearContent(); // additional info 2 

  // Client Status 
    shClient.getRange('AN5:AO5').clearContent(); // client status
    shClient.getRange('AP5:AQ5').clearContent().setValue(false); // importance


  shClientsListValuesFound = true;
  shDataValuesFound = true;
 return;
}

我假设是错误行:

 for (var j = 0; i < shClientsListValues.length; j++) {

应该是j而不是i:

 for (var j = 0; j < shClientsListValues.length; j++) {