Skip to content
Advertisement

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:

JavaScript

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

Advertisement

Answer

Usually there are two options:

  1. Check the value before:
JavaScript
  1. Try to use the value and skip any error with try/catch:
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement