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

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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