0

I am new with Google Sheets Script Editor. I am trying to get a function that returns how many time a word (in this case Mother) is present in a Bing website search. So I try this code:

function myFunction112() {
  const url = "https://www.bing.com/search?q=“Not all of us can do great things. But we can do small things with great love.”";
  const html = UrlFetchApp.fetch(url).getContentText();
  const numberOfOcurrencies = (html.match(/Mother/g) || []).length;
  console.log(numberOfOcurrencies);
  return numberOfOcurrencies;
}

The problem is that in Console it shows 18 for numberOfOcurrencies that is correct, but in my google sheet return 0. As you can see in the images below.

Script editor

Google sheet

I call my function myFunction112 to make sure no other function has the same name. How can I make my function return the same value that shows in console?

Many thanks.

  • 1
    If you exclude all other possibilities and other answers(that may come), [this](https://stackoverflow.com/questions/63024346/) may be a possibility. – TheMaster Jan 22 '21 at 21:11
  • 1
    Thanks your answer! Reading it I have decide to run my script from editor and use setValues() to update the value in Google Sheet. – Carlos Benites Jan 24 '21 at 17:13

1 Answers1

0
Supported services Notes
Cache Works, but not particularly useful in custom functions
HTML Can generate HTML, but cannot display it (rarely useful)
JDBC
Language
Lock Works, but not particularly useful in custom functions
Maps Can calculate directions, but not display maps
Properties
Spreadsheet Read only (can use most get*() methods, but not set*()).Cannot open other spreadsheets (SpreadsheetApp.openById() or SpreadsheetApp.openByUrl()).
URL Fetch
Utilities
XML

Guidelines for Custom Functions

Cooper
  • 59,616
  • 6
  • 23
  • 54