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

79
Visualizações
Google Apps Script alert not working as expected
function FindLastRowAndDate() {
  var ss = SpreadsheetApp.getActive().getSheetByName('Math');
  ss.activate();
  var LastRow = ss.getDataRange().getNumRows();
  var Date = SpreadsheetApp.getActiveSheet().getRange(LastRow, 1).getValue();
  SpreadsheetApp.getUi().alert("The Value for LastRow is ", LastRow, SpreadsheetApp.getUi().ButtonSet.OK);      
  SpreadsheetApp.getUi().alert("The Value for Date is ", Date, SpreadsheetApp.getUi().ButtonSet.OK);
} 

The first alert works fine except it shows 11.0 instead of 11 (like a simple alert without the title does). Any idea why? The second alert fails for Exception: The parameters (String,(class),ButtonSet) don't match the method signature for Ui.alert. Why; its syntax appears identical to me? Any clues/solutions gratefully received.

I've tried using const instead var, but that didn't make any difference

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

0

Description

Apparently a Ui alert can not take a Date object. You need to .toString() it or use Utilties.formatDate() to present the date value.

To remove the extra decimal digits use .toFixed().

Note, it is customary to have the first letter as lowercase in variable and function names. First letter uppercase is normally used for Object Class or global variables.

Script

function findLastRowAndDate() {
  var ss = SpreadsheetApp.getActive().getSheetByName('Math');
  ss.activate();
  var lastRow = ss.getDataRange().getNumRows();
  var myDate = SpreadsheetApp.getActiveSheet().getRange(LastRow, 1).getValue();
  SpreadsheetApp.getUi().alert("The Value for LastRow is ", lastRow.toFixed(), SpreadsheetApp.getUi().ButtonSet.OK);      
  SpreadsheetApp.getUi().alert("The Value for Date is ", myDate.toString(), SpreadsheetApp.getUi().ButtonSet.OK);
} 

Reference

  • Number.toFixed()
  • Date.toString()
  • Utilities.formatDate()
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