When I put only the following Google Apps Script in (by itself), it works properly...
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1"); // SHEET NAME
var range = sheet.getRange("A2:C"); // RANGE TO SORT
function onEdit(e) {
range.sort([{column: 3, ascending: true}]); // COLUMN NUMBER TO SORT
}
Similarly, when I put only the following Google Apps Script in (by itself), it works properly...
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) { //Checks to see if we're on Sheet1 or not
var r = s.getActiveCell();
if( r.getColumn() == 3 ) { //Checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //Checks to see if the adjacent cell is empty or not?
nextCell.setValue(new Date());
}
}
}
But when I put them both in, the first Google Apps Script works properly, but the second Google Apps Script fails to work.
What am I doing wrong?
First, I added the following after I posted my initial question based on feedback I received below
Based on best practices, I am guessing, perhaps, the combined apps script should look something like this...
function onEdit(e) {
if (!e)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1"); // SHEET NAME
var range = sheet.getRange("A2:C"); // RANGE TO SORT
function onEdit(e) {
range.sort([{column: 3, ascending: true}]); // COLUMN NUMBER TO SORT
}
if (var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) { //Checks to see if we're on Sheet1 or not
var r = s.getActiveCell();
if( r.getColumn() == 3 ) { //Checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //Checks to see if the adjacent cell is empty or not?
nextCell.setValue(new Date());
}
}
}
Second, I added the following after I posted my initial question based on feedback I received below
Based on best practices, I am guessing, perhaps, the combined apps script should look something like this...