0

I am using a custom function to keep modify a sheet's row count as data from another sheet changes. To do this, I had to put the script that does the modification into a standalone Google Apps script, since custom functions called directly from spreadsheets do not have write permission. I then call UrlFetchApp.fetch from the custom function.

Everything works as I'd expect, but the problem is for some unknown reason the script runs as if each each expression that modifies the spreadsheet waits about 10 seconds before it executes. When I call it directly from my browser using the same URL I used in UrlFetchApp.fetch, the changes happen instantaneously.

Let's say I have the following:

var sheet = SpreadsheetApp.openById(...).getSheetByName(...);
sheet.getRange(1, 1).setValue(1);
sheet.getRange(2, 1).setValue(2);

If I were to run the script from the browser, the script finishes immediately. However, when invoked from my spreadsheet, it seems to wait about 10 to 15 seconds before each setValue expression runs. Any idea why that is and how I could make it run faster?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Hao Zhang
  • 211
  • 2
  • 7
  • Maybe you should "install" an "On Edit" trigger, and run the code that way. And I don't think you would need the stand alone Web App using that strategy. But I'm not exactly sure what the initial event is that triggers the process? – Alan Wells May 24 '17 at 23:58
  • @SandyGood I would do that, but I need it to run when anonymous users use the spreadsheet. That's why I went with using a formula. I guess what I can do, if it does come to this, is to set either a timed trigger or an onEdit trigger on the source spreadsheet. – Hao Zhang May 25 '17 at 12:09

0 Answers0