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

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

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 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