-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTTL.js
More file actions
31 lines (25 loc) · 1.09 KB
/
TTL.js
File metadata and controls
31 lines (25 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function installTtl() {
ScriptApp.newTrigger("enforceTtl").timeBased().everyDays(1).create()
}
function enforceTtl() {
const form = FormApp.getActiveForm()
const lastRun = new Date(PropertiesService.getScriptProperties().getProperty("ttlLastRun") || 0)
console.info("Enforcing TTL on everything since " + lastRun)
form.getResponses().map(mapResponse)
.filter(function(response) {
return response.start.valueOf() < new Date().valueOf() && response.start.valueOf() > lastRun.valueOf()
})
.forEach(update)
PropertiesService.getScriptProperties().setProperty("ttlLastRun", new Date())
}
function update(response) {
const calendar = CalendarApp.getCalendarById(targetCalendar);
const eventId = PropertiesService.getDocumentProperties().getProperty(response.id + "_event");
const event = eventId && calendar.getEventById(eventId)
if(event) {
console.info("Updating event description for " + response.title)
response.formUrl = event.getTag("formUrl");
response.responsesUrl = event.getTag("resultsUrl");
updateCalendarEvent(event, response)
}
}