Last active
March 11, 2020 15:33
-
-
Save tsamb/80883f6cba70c659b63e55916be7e08e to your computer and use it in GitHub Desktop.
A dev console pasteable script for creating a CSV from the Airtable record history/activity panel
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
// In Airtable, expand a record and make sure its activity panel is expanded. | |
// Click "Show more" at the top of the activity panel until you get to the beginning of the record's history. | |
// Press Ctrl+Shift+J (on PC) or Cmd+Opt+J (on Mac) in your Chrome browser to pull up the JavaScript console. | |
// Paste the below script into the console to download the activity history as a CSV. | |
function arrayToCSV(nestedArray, exportName) { | |
const filename = exportName || "exported_js.csv"; | |
const csvString = nestedArray.map((row) => row.map((field) => '\"' + field + '\"').join(',')).join('\r\n'); | |
let a = document.createElement('a'); | |
a.href = 'data:attachment/csv,' + encodeURIComponent(csvString); | |
a.target = '_blank'; | |
a.download = filename; | |
document.body.appendChild(a); | |
a.click(); | |
a.remove(); | |
} | |
function getVisibleActivity() { | |
return Array.from( | |
document.querySelectorAll(".rowLevelActivityFeed .py1.baymax")).map((el) => { | |
let authorAndTimestamp = el.querySelector(".flex.line-height-4.mb-half").title; | |
let fieldName = el.querySelector(".micro.strong.caps").innerText; | |
let fieldValue = el.querySelector(".historicalCellValueContainer").innerText; | |
let [_, author, __, ___, timestamp] = authorAndTimestamp | |
.match(/(.+) (edited|created) (this record|via API|by modifying a field) on (.+)/); | |
return [ | |
author, | |
timestamp, | |
fieldName, | |
fieldValue | |
]; | |
} | |
) | |
} | |
arrayToCSV(getVisibleActivity()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment