Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

388
Visualizações
TypeError: Cannot read property 'getRow' of null Google Script

I am getting a TypeError when running this. I can't figure out why..

function iceHorsepowerInjector() {  
  let z = 0;
  let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('blah blah blah');
  let sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('blah blah blah')
  let sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('blah blah blah')
  for (let i = 2; i <= 1312; i++) { 
    let handle = sheet.getRange("A"+[i]).getValue(); 
    if (handle == null){
      continue;
    } else {                                                     
    var index = sheet1.createTextFinder(handle).matchEntireCell(true).findNext().getRow(); // <---- this is where I am getting the error
    }
    if (handle == null){
    continue;
    }
    index = parseInt(index);
    let horsepower = sheet1.getRange("EE"+[index]).getValue();
    if (horsepower == "NULL"){
      continue;
    }                                            
    let id = sheet.getRange("CQ"+[i]).getValue();
    if (id == "#N/A"){
      continue;
    }                                                        
      var commands = ("UPDATE fossil_fuel_vehicle_trims SET horsepower" + "=" + "'"+horsepower+ "' WHERE id =" + handle +";")
      sheet2.getRange(1+z,1).setValue(commands);   //set to last row used in sheet3
      z = z + 1
  }   
}

This is the error..

    
TypeError: Cannot read property 'getRow' of null
iceHorsepowerInjector   @ Code.gs:11

How do I fix this? I feel as if I'm close but I can't seem to figure out why this is happening.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The error occurs because sheet1.createTextFinder(handle).matchEntireCell(true).findNext() returned null.

One simple fix for this error is to replace

var index = sheet1.createTextFinder(handle).matchEntireCell(true).findNext().getRow(); // <---- this is where I am getting the error
}
if (handle == null){
continue;
}

by

var found = sheet1.createTextFinder(handle).matchEntireCell(true).findNext();
}
if (found == null){
continue;
}
var index = found.getRow();
    
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda