function oneWeek() {
var sheetURL = SpreadsheetApp.getActive().getUrl()
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]);
var sheet = spreadsheet.getActiveSheet();
// do stuff with sheet
}
How do I get this function to trigger onEdit?
I've tried this for the sheet,
function onEdit(event) {
var sheet = event.source.getSheetByName('x');
// do stuff with sheet
}
EDIT: I forgot to mention that my script did https request so that's the reason onEdit didn't work. The solution is here: https://productforums.google.com/forum/#!topic/docs/0nxLYWXVo6Y
Because this script does other things, like a HTTP request, it cannot be assigned to the default onEdit() functions, you need to create it as a custom function and assign it in the Edit menu. Edit->Current Project Triggers and create a new one for onEdit. Just point it at your function and you’re done.