Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

76
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!