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

422
Views
getValue() function not returning anything in Google Scripts for Sheets

I'm trying to use google scripts to select a random row from google sheets and return some of the cell values in those rows to email to me.

Here's what I have so far:

function sendEmails() {

  var ss = SpreadsheetApp.openById('x');
  var sheet = ss.getSheetByName('report');

  var numRows = sheet.getLastRow();
  var randomRow = Math.floor(Math.random() * numRows); 

  var bodyTitle = sheet.getRange(3, randomRow).getValue();
  var bodyHighlight = sheet.getRange(4, randomRow).getValue();
  var bodyLink = SpreadsheetApp.getActiveSheet().getRange(2, randomRow).getValue();
  
  // var bodyTest = SpreadsheetApp.getActiveSheet().getRange(2, 2).getValue();

  var body = bodyTitle + " | " + bodyLink + " | " + bodyHighlight ; 
  var recipient = "x@gmail.com";
  var subject = "resurfaced highlights";

  MailApp.sendEmail(recipient, subject, body);

}

However when I receive the email all I get in the body is "| |" which makes it seem as though the getValue() functions for the bodyTitle, bodyHighlight, and bodyLink variables are not working. Any help would be appreciated!

Thanks.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem is in the order of the parameters.

It is supposed to be getRange(row, column) not getRange(column, row)

Just swap the order of the parameters.

Reference:

  • getRange(row, column)
about 4 years ago · Santiago Trujillo 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!