The undo() function for Google Apps Script is currently not available in the Table / Sheet / Range classes. There were several problems in "Tracking Problems", I can only find them now (I donโt know what Triaged is): here .
Workarounds were suggested using DriveApp and change history, but I looked around and found nothing (maybe he buried?). In any case, the undo() function is incredibly necessary for many different operations. I could only think of one workaround, but I was not able to get it to work (way to store data, I don't know if this is possible). Here are a few pseudo -
function onOpen () { // Get all values in the sheet(s) // Stringify this/each (matrix) using JSON.stringify // Store this/each stringified value as a Script or User property (character limits, ignore for now) } function onEdit () { // Get value of edited cell // Compare to some value (restriction, desired value, etc.) // If value is not what you want/expected, then: // -----> get the stringified value and parse it back into an object (matrix) // -----> get the old data of the current cell location (column, row) // -----> replace current cell value with the old data // -----> notifications, coloring cell, etc, whatever else you want // If the value IS what you expected, then: // -----> update the 'undoData' by getting all values and re-stringifying them // and storing them as a new Script/User property }
Basically, when the table opens, save all the values โโas the Script / User property, and refer only to them when certain cell criteria (on) are met. When you want to cancel, get the old data that was saved in the current cell and replace the current cell value with the old data. If the value does not need to be undone, update the saved data to reflect the changes made to the spreadsheet.
Until now, my code has been a bust, and I think because the structure of nested arrays is lost when the object is contracted and saved (for example, it is not parsed correctly). If someone wrote this feature, share it. Otherwise, suggestions for writing this will be helpful.
Change These documents are incredibly static. The number of rows / columns will not change, as well as the location of the data. Implementing the get-all-data / store-all-data-type function for a temporary change history will really satisfy my needs, if possible.