Last active
May 25, 2019 23:28
-
-
Save seanli1/d2fdf61e23456b19faec7a35452beafe to your computer and use it in GitHub Desktop.
Changelog script for Google Sheets (see warning)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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