Try this
function onEdit(e){
let ss = SpreadsheetApp.getActiveSpreadsheet();
let users = ss.getEditors();
let date = new Date();
let sh = e.source.getActiveSheet();
let shName = sh.getSheetName();
let cell = e.range;
let cellData = cell.getValue();
let col = cell.getColumn();
let row = cell.getRow();
let emailCell = sh.getRange(row, 4).getValue();
let dateCell = sh.getRange(4, 5).getValue();
if( shName === 'Charter Dashboard' && col == 1 && row >= 2 && ( cellData === 'Approved' || cellData === 'Declined') && (emailCell == "" || dateCell == "") ){
for(i=0; i<users.length; i++){
if(Session.getActiveUser().getEmail() == users[i].getEmail() ){
sh.getRange(row, 4).setValue(users[i].getEmail() );
sh.getRange(row, 5).setValue(date);
}
}
}
}
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2d943656-7b35-44e8-b1e7-88dbc7c9d83fn%40googlegroups.com.
Here's my test sheet. It's view only. Make a copy so that you become owner with editor's rights and then try it yourself. You will need to give permissions for the script to run.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/b6210d73-adba-4e93-b2ff-5f2f964e5b97n%40googlegroups.com.
When you get that error. Are you getting it by running it in the script editor or by changing the value in the column?
I'm kind of at a loss because I wrote that on a sheet and tested it several times and it worked on my end.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/b6210d73-adba-4e93-b2ff-5f2f964e5b97n%40googlegroups.com.
Yes, on edit will always give an error in the script editor because it needs an actual edit on the sheet in order to run.
You're very welcome.
Cheers
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/8342eaeb-07bd-4b76-bf2a-68b335430190n%40googlegroups.com.