Action
Import Calendar Events
UPDATES
almost 3 years ago
Fixed time zone issue
Steps
-
script
let calendars = Calendar.getAllCalendars(); let calendarNames = calendars.map(x => x.title); let p = Prompt.create(); p.title = "Import Calendar"; p.message = "Select calendar and date range to import events from the calendar as a Mardown lst"; p.addSelect("calendar", "Calendar", calendarNames, [], false); p.addDatePicker("start","Start date", (1).years().ago(), {"mode":"date"}); p.addDatePicker("end","End date", Date.today(), {"mode":"date"}); p.addButton("Import"); if (p.show()) { let selected = p.fieldValues["calendar"]; let ix = calendarNames.findIndex(x => x == selected); let cal = calendars[ix]; let start = p.fieldValues["start"]; let end = Date.parse(p.fieldValues["end"]).addMilliseconds(86399999); if (cal) { if (!importCal(cal, start, end)) { context.fail(); } } } else { context.cancel(); } function importCal(cal, start, end) { let events = cal.events(start, end); if (events == "undefined" || events.length == 0) { alert('No events found to import'); return false; } let t = [] for(let event of events) { t.push("* " + event.title + " - "); if (event.isAllDay) { t.push(" - All Day " + "/n"); } else { if(event.startDate.getHours()>11) { let Hours = event.startDate.getHours() - 12; t.push(Hours + ":"+ event.startDate.getMinutes() + " PM"); } else { t.push(event.startDate.getHours()+ ":"+ event.startDate.getMinutes()+ " AM"); } } t.push('\n'); } //let d = Draft.create(); draft.append(t.join("")); //draft.content = t.join(""); //draft.update(); //editor.load(d); return true; }
Options
-
After Success Default Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.