hideSheet() being executed, but not actually hiding the sheet
Clash Royale CLAN TAG#URR8PPP
hideSheet() being executed, but not actually hiding the sheet
I am running this function i made in Google Apps Script for a spreadsheet add-on. It does everything right, but every OTHER execution it doesn't hide the sheet. Any ideas?
function addEmailNew(formObject)
var newEmail = formObject.addEmailText;
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.getSheetByName("No Touching!").activate();
//find the last string value in a column
var Avals = ss.getRange("J:J").getValues();
var Alast = Avals.filter(String).length + 1;
ss.getSheetByName('No Touching!').getRange("J" + Alast).setValue(newEmail);
//THIS IS THE THING THAT WORKS EVERY OTHER TIME
SpreadsheetApp.getActiveSheet().hideSheet();
openDialog();
return Logger.log("this did stuff");
1 Answer
1
It's fine to get the active sheet, but prior to hide it, activate another sheet. Try something like the following:
var sheetToHide = SpreadsheetApp.getActiveSheet();
ss.getSheetByName("Other sheet").activate();
sheetToHide.hideSheet();
If the problem persists, add SpreadsheetApp.flush();
on a new line after hideSheet()
.
SpreadsheetApp.flush();
hideSheet()
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks for the help Ruben. Sadly neither activating another sheet nor putting in the flush method worked :(
– Douglas Fordham
Aug 6 at 16:07