I have a bit of script to capture changes made to a table of information, pulling the new value as well as the person's ID, a category, and the reference of the item being changed. Altogether the script collects 4 snippets of data, plus a timestamp. Once collected, this array is appended to the bottom of a table on another sheet to act as a change log. Once done, the changed cell is formatted yellow to show it's been changed.
It works, but if you change another cell too quickly afterwards, the script trips over and one or more subsequent changes are not captured. How can I "bank" the changes, and write them to the second sheet once all the changes are made? (eg by clicking a "save" button) I am self taught so have big holes in my knowledge, so any helpful suggestions (with examples) gratefully received.
code:
function onEdit(e){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ViewId = ss.getSheetByName('VIEW').getSheetId(); // Sheet ID of the only sheet this script applies to
const ThisSheetId = ss.getActiveSheet().getSheetId(); // Sheet ID of whichever sheet is active
const SignedOff = ss.getSheetByName('SignedOff'); // Sheet on which the collected data is to be appended
if(ViewId == ThisSheetId){
// Exit if we're on the wrong page
var ThisRow = e.range.getRow();
var ThisCol = e.range.getColumn();
if (ThisRow >= 4 && ThisCol >= 3){
// Exit if we're out of range so only changes within the table are registered
var NewValue = e.range.getValue();
var IndividualID = VIEW.getRange(ThisRow,1,1,1).getValue(); // get value from column A of the edited line
var ItemName = VIEW.getRange(2,ThisCol,1,1).getValue(); // get header value from the edited column
var Category = VIEW.getRange('J1').getValue(); // get value showing which category the item is from
var Timestamp = new(Date);
SignedOff.appendRow([IndividualID,Category,ItemName,NewValue,Timestamp]); // add the collected data to the list on the SignedOff sheet
e.range.setBackground('#ffff00'); // turn the edited cell yellow to show it's been changed
} return
}return
}