I am trying to run a Google Script to delete unused filter views. I found the script on Stackoverflow
function delUnusedFilterViews() {
var ssId = SpreadsheetApp.getActive().getId();
var sheetName = SpreadsheetApp.getActiveSheet().getName();
SpreadsheetApp.getActiveSpreadsheet().toast('Removing unnamed Filters from sheet: ' + sheetName);
var allFilters = Sheets.Spreadsheets.get(ssId).sheets[0].filterViews;
var filterArr =[];
for (var i in allFilters) {
var currFilter = allFilters[i];
var filterName = currFilter.title;
var currFilterId = currFilter.filterViewId;
if (/Filter [0-9]/.test(filterName)) filterArr.push({ deleteFilterView: { filterId: currFilterId } })
}
Sheets.Spreadsheets.batchUpdate({
requests: filterArr
},
ssId
)
Browser.msgBox("All Done. You need to reload the sheet to see the filters have been deleted");
}
I've never run a Google Script before, so I went through the process of adding in the "Sheets" services. However, I'm getting this error when I run it and I don't know what's going wrong:
GoogleJsonResponseException: API call to sheets.spreadsheets.batchUpdate failed with error: Must specify at least one request.