はじめに
標題通り、Gasでカレンダー情報を取得します。特定のカレンダーで、会議室管理、イベント管理を実施したいと考えています。色々工夫したので、メモ程度にコードを残しておきます。
ファイル一覧
ファイル一覧
getCalendar.gs //カレンダー取得
color.gs //色の定義
constants.gs // 定数
model.gs // model
ソースコード
getCalendar.gs
// 本日の会議室一覧の予約取得
function getTodayMTGList() {
const googleCalendar = CalendarApp.getCalendarById(CALENDAR_ID);
const nowDate = new Date()
// 本日のイベント一覧取得
const calendarEvents = googleCalendar.getEventsForDay(nowDate)
// MTGの色(1)でフィルターを実施
const mtgs = calendarEvents.filter(mtg => mtg.getColor() === EVENT_COLOR)
const results = []
for(const event of mtgs){
const calendar = new Calendar()
calendar.title = event.getTitle()
calendar.startTime = event.getStartTime()
calendar.endTime = event.getEndTime()
calendar.description = event.getDescription()
calendar.type = MTG_TYPE
results.push(calendar)
}
return results
}
color.gs
const EVENT_COLOR = CalendarApp.EventColor.PALE_BLUE // 1
const MTG_COLOR = CalendarApp.EventColor.PALE_GREEN // 2
// =======================【色のプロパティ】===========================
// 色名称:色表示名:色のID
// Pale_Blue:ラベンダー:1
// Pale_Green:セージ:2
// Mauve:ブドウ:3
// Pale_Red:フラミンゴ:4
// Yellow:バナナ:5
// Orange:ミカン:6
// Cyan:ピーコック:7
// Gray:グラファイト:8
// Blue:ブルーベリー:9
// Green:バジル:10
// Red:トマト:11
constants.gs
const CALENDAR_ID = PropertiesService.getScriptProperties().getProperty("CALENDAR_ID");
const MTG_TYPE = "mtg"
const EVENT_TYPE = "event"
model.gs
/** Calendarモデルの定義 */
function Calendar() {
this.title = null;
this.startTime = null;
this.endTime = null;
this.description = null;
this.type = null
}
実行ログ
実行ログ
results: [ { title: '2階会議室予定',
startTime: Sat Feb 04 2023 20:00:00 GMT+0900 (Japan Standard Time),
endTime: Sat Feb 04 2023 21:00:00 GMT+0900 (Japan Standard Time),
description: '説明実施',
type: 'mtg' } ]