Google Apps Script returns desired result in execution log, but cell in spreadsheets is empty

0

On this spreadsheet, the Apps Script returns the right result when I run it, the execution log correctly returns "202000.0".

However, when I run the script in a cell (highlighted in orange on the linked spreadsheet), the cell is empty, does anyone know how to fix this by any chance?

The Apps Script code:

function fullTimeEmployees(url) {
  var url = 'https://finance.yahoo.com/quote/WBA/profile'
  var source = UrlFetchApp.fetch(url).getContentText()
  var jsonString = source.match(/root.App.main = ([\s\S\w]+?);\n/)
  if (!jsonString || jsonString.length == 1) return;
  var data = JSON.parse(jsonString[1].trim())
  Logger.log(data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees)
}

Also, does anyone know what I can change .fulltimeEmployees (at the end) to so it returns the full company name? as pictured here, highlighted in green company name section

1

1

Answer for question 1:

However, when I run the script in a cell (highlighted in orange on the linked spreadsheet), the cell is empty, does anyone know how to fix this by any chance?

In your script, no value is returned. This is the reason of your issue. So please modify your script as follows.

function fullTimeEmployees(url) {
  var url = 'https://finance.yahoo.com/quote/WBA/profile'
  var source = UrlFetchApp.fetch(url).getContentText()
  var jsonString = source.match(/root.App.main = ([\s\S\w]+?);\n/)
  if (!jsonString || jsonString.length == 1) return;
  var data = JSON.parse(jsonString[1].trim())
  Logger.log(data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees)
  return data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees; // Added
}

Answer for question 2:

Also, does anyone know what I can change .fulltimeEmployees (at the end) to so it returns the full company name? as pictured here, highlighted in green

In this case, how about modifying as follows?

From:

data.context.dispatcher.stores.QuoteSummaryStore.assetProfile.fullTimeEmployees

To:

data.context.dispatcher.stores.QuoteSummaryStore.price.shortName
  • The value of this is Walgreens Boots Alliance, Inc..
2021-11-23 23:59:44

You are an absolute star!! I genuinely can't thank you enough, as a novice with coding I've spent numerous hours trying to achieve this end goal so I really appreciate your help in finally getting there.
DarkWingDuck

@DarkWingDuck Thank you for replying and testing it. I'm glad your issue was resolved. Thank you, too.
Tanaike

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................