Search code examples
javascriptgoogle-apps-scriptgoogle-sheetsgoogle-sheets-formulagoogle-apps

Does google sheet needs to be opened for a function to run?


I have a google sheet where there are some functions in the cell like:

    =CLEAN(SUBSTITUTE(CONCATENATE("https:",scrape(A1)),"https:",))
 =CLEAN(SUBSTITUTE(CONCATENATE("https:",scrape(B1)),"https:",))

and behind the scenes I have script function running that pulls the output of the cells (after scrape function runs) and pushes the value to a 3rd party database via API.

I have the script functions running periodically by this approach:

ScriptApp.newTrigger('API_Data_push_function')
.timeBased()
.everyHours(24)
.create();

but I have noticed in the 3rd party database that values are coming like

#NAME?

But when I open the google sheet and run the script function manually, it runs fine.

So, I am trying to understand if google sheet UI needs to be opened for cell functions to run properly? OR if the issue is the API data push function is running faster than cell function which is returning #NAME? value.

Can anyone confirm if google sheet needs to be opened for cell functions to work? if yes, any way for script to force cell function to run first prior to script to start running?


Solution

  • No...But you might need to use SpreadsheetApp.flush() in your scripts to make sure that when you read values off of the spreadsheet after intermediate operations that your getting the correct values.