0
votes
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.

1
Directly from the documentation: onEdit(e) runs when a user changes a value in a spreadsheet. - It will run if a user makes any change to any cell on any sheet. You can limit when you run the function by returning for any sheet except the ones you want it to run on. Note: you can't test the onEdit(e) by running it in the script editor.ReferenceCooper

1 Answers

1
votes
function onEdit(e){
if(e.range.getSheet().getName()!='x'){return;}
//do stuff on sheet x here
}