Skip to content

Instantly share code, notes, and snippets.

@seanli1
Last active May 25, 2019 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanli1/d2fdf61e23456b19faec7a35452beafe to your computer and use it in GitHub Desktop.
Save seanli1/d2fdf61e23456b19faec7a35452beafe to your computer and use it in GitHub Desktop.
Changelog script for Google Sheets (see warning)
// WARNING: This will cause issues with the Undo function.
function onEdit(e) {
// Set sheet name (it must already exist):
var sheetName = "Changelog"
// e contains:
// - authorized mode
// - range
// - source
// - user
// - value
// Get sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName)
// Set values
var formattedDate = Utilities.formatDate(new Date(), "GMT-5", "yyyy-MM-dd HH:mm:ss");
var source = "\"" + e.source.getSheetName() + "\""
var range = e.range.getA1Notation()
var values = [formattedDate, source, range, e.value]
// Set cells
var nextRow = sheet.getLastRow() + 1
for(var col = 1; col <= values.length; col++) {
sheet.getRange(nextRow, col).setValue(values[col-1])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment