Created
July 29, 2019 21:43
-
-
Save keccers/26f6d50ce1d7ea0218a1171a5f86e9ea to your computer and use it in GitHub Desktop.
Google Calendar x Google Sheets AppScript Plugin
This file contains 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
function updateEvents() { | |
// Get Sheet and Calendar | |
var spreadsheet = SpreadsheetApp.getActiveSheet(); | |
var postCal = CalendarApp.getCalendarById('talentinc.com_hq7sgaqvp5kjgu7a865n4j91tc@group.calendar.google.com'); | |
// Get data from Sheet | |
var data = spreadsheet.getDataRange().getValues() | |
var posts = [] | |
// This loop parses the data from the spreadsheet and adds it to an array | |
for (var i = 1; i < data.length; i++) { | |
// Skips blank rows | |
if (data[i][0] == "") { | |
break | |
} | |
// Uses the first row, headers, as keys with the values being assigned to each. Then the object is pushed onto the array. | |
//Pulls in publish date, article title, brand, and Asana Task | |
var post = {} | |
post[data[0][2]] = data[i][2] | |
post[data[0][4]] = data[i][4] | |
post[data[0][5]] = data[i][5] | |
post[data[0][14]] = data[i][14] | |
posts.push(post) | |
} | |
// Loops through the array of events and creates the correct calendar entries for each post publish date. | |
for (var i = 0; i < posts.length; i++) { | |
// Calendar entries are colored differently depending on which brand they represent. | |
if (posts[i]["Brand"] == "TR") { | |
postCal.createAllDayEvent(posts[i]["Title"], posts[i]["Pub_Date"], { description: "Asana Task: " + posts[i]["Asana Task"]}).setColor(CalendarApp.EventColor.ORANGE) | |
Logger.log("Created TopResume Post") | |
} else if (posts[i]["Brand"] == "TI") { | |
postCal.createAllDayEvent(posts[i]["Title"], posts[i]["Pub_Date"], { description: "Asana Task: " + posts[i]["Asana Task"]}).setColor(CalendarApp.EventColor.RED) | |
Logger.log("Created TopInterview Post") | |
} else { | |
postCal.createAllDayEvent(posts[i]["Title"], posts[i]["Pub_Date"], { description: "Asana Task: " + posts[i]["Asana Task"]}).setColor(CalendarApp.EventColor.GREEN) | |
Logger.log("Created TopCV Post") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment