I cannot find any detailled documentation on the event.source object so I would like to know if it's possible to access the previous value of the modified range so I can compare the new values of the range with the old values of the range for validation.
Thanks for your help.
OnEdit(event)
function onEdit(event)
/* Default onEdit Event function */
{
var ssa = SpreadsheetApp.getActiveSpreadsheet();
var ss = event.source.getActiveSheet();
var r = event.source.getActiveRange();
...
You could make use of ScriptDB to store the information
onLoad()
and then read it backonEdit()
. Each time there is an edit you could then callonLoad()
again to refresh the database of the cell values again or just replace the relevant information in the database.Add
notonEdit()
to trigger on a FromSpreadsheet>onEdit() event in the Resources>All Your Triggers menu.Here is the code:
--edit it seems this is now possible, please take look at the links and comments bellow.
Detailed information is on documentation here.
But the previous value is not available on the event. There's an enhancement request opened regarding this. You should "star" it to keep track of updates and kind of vote for it.
Now, to "workarounds". All of them are based on the fact that you will have to save the original data yourself somewhere else. You can have a mirror spreadsheet or sheet and when any
onEdit
happens on the original you can go to the mirror and get the old value. This is a little more complicated than it seems, because you'd also have to update the mirror spreadsheet via the script, but not all events on spreadsheet triggersonEdit
events, e.g. inserting rows. So your script has to be extra smart to keep up with those, which, depending on your usage, may not even be possible.