I can't seem to figure out how I can use the variable from my onSelectionChange function in the onEdit function. I want to append the cell values into another cell to retain its history but I don't want the current update to be in the history. I tried using PropertiesService but I can't get it to work. Could someone please help?
var latest_update;
var latest_date;
var updates_history;
function onSelectionChange(e){
var row = e.range.getRow();
var col = e.range.getColumn();
if (col == 3){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
updates_history = ss.getRange(e.range.getRow(),col + 2).getValue(); //store column E value, Updates History
latest_update = ss.getRange(e.range.getRow(),col).getValue(); //store column C value, Latest Update value
latest_date = ss.getRange(e.range.getRow(),col + 1).getValue(); //store column D value, Latest Update Date
} else { return;}
}
function onEdit(e){
onSelectionChange(e);
var row = e.range.getRow();
var col = e.range.getColumn();
if (col ==3){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
ss.getRange(e.range.getRow(),col + 2).setValue(latest_date + ": " + latest_update + "\n" + updates_history); //append Latest Update and Latest Update Date to Updates History
} else {return;}
}