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

290
Vistas
UrlFetchApp.fetch() skip on empty cell

I've written a script that gets an image url from a cell in Google Sheets and adds that image to a template in Google Docs. However, when the cell is empty, the script crashes:

var beforePhoto1 = UrlFetchApp.fetch(row[14]).getBlob();

Really new to programming and would appreciate anyones help as to how to prevent the above code from crashing in the event a cell is empty

over 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Usually there are two options:

  1. Check the value before:
if (row[14] != '') {
  var beforePhoto1 = UrlFetchApp.fetch(row[14]).getBlob();
} else {
  console.log('row[14] was empty');
  var beforePhoto1 = 'default_value';
}

// rest code
  1. Try to use the value and skip any error with try/catch:
try {
  var beforePhoto1 UrlFetchApp.fetch(row[14]).getBlob();
} catch(e) {
  console.log('row[14] was empty');
  var var beforePhoto1 = 'default_value';
}

// rest code
over 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
Asistente virtual