The following script will hide any rows on a sheet if Col Q has "YES" in it.
function AutoHidingTechnique() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.showRows(1, sheet.getLastRow());
var range = sheet.getRange("Q1:Q" + sheet.getLastRow());
var values = range.getValues();
var numRows = range.getNumRows();
for (var i = 0; i < numRows; i++) {
if (values[i][0] === "YES") {
sheet.hideRows(i+1);
}
The script used to work perfectly (for months) on an hourly time-driven trigger.
Lately the execution log affirms the script is still working fine, but the rows are not being hidden anymore.
When I run the script manually, however from the menu or editor, it does hide the rows.
The fact that the time-driven script used to work perfectly and the script still works perfectly when ran manually leaves me at a loss as to how get the time-driven hourly trigger to actually do what it says it is doing.
Why is that and how can I fix it?
The following script will hide any rows on a sheet if Col Q has "YES" in it.
function AutoHidingTechnique() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.showRows(1, sheet.getLastRow());
var range = sheet.getRange("Q1:Q" + sheet.getLastRow());
var values = range.getValues();
var numRows = range.getNumRows();
for (var i = 0; i < numRows; i++) {
if (values[i][0] === "YES") {
sheet.hideRows(i+1);
}
The script used to work perfectly (for months) on an hourly time-driven trigger.
Lately the execution log affirms the script is still working fine, but the rows are not being hidden anymore.
When I run the script manually, however from the menu or editor, it does hide the rows.
The fact that the time-driven script used to work perfectly and the script still works perfectly when ran manually leaves me at a loss as to how get the time-driven hourly trigger to actually do what it says it is doing.
Why is that and how can I fix it?
Share Improve this question edited Feb 2 at 18:24 Wicket 38.4k9 gold badges78 silver badges193 bronze badges asked Jan 31 at 22:58 sbraddsbradd 92 bronze badges 4 |1 Answer
Reset to default 0Posting a Comment as an Answer
When we use trigger the active sheet is Spreadsheet.getSheets()[0]
to make things work as intended to use the specific sheet that we wanted we need to specify what sheet were gonna use by using getSheetByName(name)
instead of getActiveSheet()
.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // returns the first sheet of the spreadsheet.
var sheet = SpreadsheetApp.getActive().getSheetByName(name); // returns the specific sheet of the spreadsheet.
Reference:
- Class SpreadsheetApp
console.log(sheet.getName());
to see which sheet is being returned as the trigger runs. Try changinggetActiveSheet()
togetSheetByName(name)
to see if that works. – Saddles Commented Feb 1 at 1:11