Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Apps Script refresh sheet while function is running

I have some script in my Google Sheets/ It can take a lot of time to finish all this script (up to 5 minutes I think). And I want to show some message that user should just wait a little. So I have some code like:

function test(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var cell = sheet.getRange("A1");
  sheet.clear();
  cell.setValue('WAIT!!!!');
  DATA = UrlFetchApp.fetch(url);
  // And some action that takes a lot of time ....
  cell.setValue('DONE!!!!');

But it doesn't show "WAIT" it only shows me "DONE" when everything is ok. It can only show me "WAIT" if there was any error and function crashed. It looks like I need to refresh it somehow.

like image 613
GhostKU Avatar asked Feb 15 '17 17:02

GhostKU


1 Answers

Call the flush()method after you set the cell value to wait.

SpreadsheetApp.flush(); //Applies all pending Spreadsheet changes.
like image 177
Hink Avatar answered Sep 26 '22 06:09

Hink