Рет қаралды 9,209
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)
docs.google.co...
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);
}
Connect with me:
• spencer.farris@gmail.com
• spencerfarris.me
• www.linkedin.com/in/spencer-farris/
• Twitter @FarrisSpencer
• Google Product Expert support.google.com/docs/profile/12305