Maryth R
Maryth R

Reputation: 3

How to skip a UrlFetchApp when the url is empty and still run the script

Sometimes there will be no url available to fetch, basically sometimes I will add an image and other times I will not, but I still would like the rest of the script to run. At the moment the lack of the url is stopping the entire thing.

I am getting this error when there is no available url to fetch in A1Image cell:

Error Exception: Attribute provided with no value: url

Are there different methods to make the script run and pretty much ignore/skip the Url Fetch App fetch (A1Image) only when A1Image cell is empty?

Here is the script part to show A1Image url as an image in the PDF:

// Insert image1
 var element = body.findText("Image1").getElement(); 
 var blob = UrlFetchApp.fetch(A1Image).getBlob(); 
 var image = element.getParent().asParagraph().insertInlineImage(0, blob); 
  image.setHeight(400);
  image.setWidth(600);

Upvotes: 0

Views: 221

Answers (1)

Cooper
Cooper

Reputation: 64082

if(A1Image) {
   var blob = UrlFetchApp.fetch(A1Image).getBlob(); 

Upvotes: 1

Related Questions