Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

82
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda