Multiple onEdit Events

How to run multiple onEdit events in the same script.
Important notes:
* It was not shown in the video, but you cannot have more than one function of the same name in the same script.
* The actual events used in my Sheet are less important than the construction.

Sheet (to copy from File – Make a copy)
https://docs.google.com/spreadsheets/…

Script
function onEdit(e) {
if (!e)
throw “Do not run onEdit from script editor”;
const src = e.source.getActiveSheet();
const r = e.range;
assignedDatetime(src,r);
moveProcessed(src,r);
}

function assignedDatetime(src, r) {
if (src.getName() != “Incoming” || r.columnStart != 2) return;
r.offset(0, 1).setValue(new Date());
}

function moveProcessed(src, r) {
if (src.getName() != “Incoming” || r.columnStart != 4) return;
const dest = SpreadsheetApp.getActive().getSheetByName(“Processed”);
r.offset(0, -3, 1, 4).moveTo(dest.getRange(dest.getLastRow() + 1, 1, 1, 4));
src.deleteRow(r.rowStart);
}

Leave a Reply

Your email address will not be published. Required fields are marked *