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

226
Visualizações
How to fix type error in google app script

I have the following function in a google app script running on a google sheet.

function GetRecords(username) {
  var ss= SpreadsheetApp.getActiveSpreadsheet();
  var displaySheet = ss.getSheetByName("DISPLAY SHEETS");
  var getLastRow =  displaySheet.getLastRow();
  var gradeArray = [];
  for(var i = 2; i <= getLastRow; i++)
  {
    var gradeSheetName = displaySheet.getRange(i, 1).getValue();
    var gradeSheet = ss.getSheetByName(gradeSheetName);
    var getLastRowGrade =  gradeSheet.getLastRow();
    for(var y = 2; y <= getLastRowGrade; y++)
    {
      if(gradeSheet.getRange(y, 1).getValue().toUpperCase() == username.toUpperCase())
      {
        var grade = gradeSheet.getRange(y, 2).getValue();
        gradeArray.push([username.toUpperCase(), gradeSheetName, grade]);
      }
    }
  }
  return gradeArray;  
}

It was working fine up until yesterday, where it now returns the following type error:

TypeError: gradeSheet.getRange(...).getValue(...).toUpperCase is not a function
    at GetRecords(Code:17:47)

Any ideas on how to fix this?

Thanks

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

0

Explanation:

getValue() can return Number, Date, Boolean, or String data type depending on the cell value. Your cell contained a non-string value so it cannot be converted to uppercase.

You could manually convert the value to String first:

gradeSheet.getRange(y, 1).getValue().toString().toUpperCase()

Sample:

enter image description here

Reference:

Class Range | getValue()

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