Joshua Roberts
Joshua Roberts

Reputation: 53

How can I correct my script to toggle a given cell from TRUE > FALSE > TRUE?

When I run my script, I want it to write TRUE and then FALSE in cell A1. It doesn't toggle when I run it. I want it to cycle through in one pass. Thanks!

function myFunction() {

 var sheet = SpreadsheetApp.getActiveSpreadsheet();
 var sh0 = sheet.getSheets()[0];
 var sh1 = sheet.getSheets()[1];
 var testRange = sh0.getRange("A1");
 testRange.setValue("TRUE");
Utilities.sleep(10000);
 testRange.setValue("FALSE");


}

Upvotes: 0

Views: 79

Answers (1)

Steve Bazyl
Steve Bazyl

Reputation: 11692

Add SpreadsheetApp.flush() in between.

CHanges to the sheet are buffered which is why you're not seeing the changes immediately. Calling flush forces any pending changes to be written to the sheet immediately.

Upvotes: 2

Related Questions