Is there a way to get the original value of a cell in onEdit()?
google-apps-script, triggers
Solution
You can use onEdit(e) and e.oldValue if you're dealing with a single cell. The example below adds the original value to A1 when any cell is edited. 'undefined' if the cell was blank.
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = sheet.getActiveCell();
var origValue = e.oldValue
sheet.getRange('A1').setValue(origValue);
}
Problem
I'd like to know if there's a way to get the original value of the cell from within the onEdit() event. For example: - Cell A1's current value is "hello" - I edit A1 it by changing it to "world" - Right now, when I try to get the value from the active range, I'd get "world" But I would also like to have the possibility to get the original value, i.e. "hello". Is that currently possible?