LoginSignup
0
0

More than 3 years have passed since last update.

GASでカレンダーのイベント作成者一覧(重複なし)を出力する。

Posted at

googleカレンダーを用いて、備品や会議室の予約表を使っています。
トラブルなどでしばらくそれらが利用できない場合、"使えなくなってしまったので代替手段を取ってちょんまげ"メールを出すことがありますね。
カレンダーを利用している全員に出しても良いのですが、予約している(イベント登録している)人だけに伝えると、スマートかなと思いました。

*と記事を書いてて、利用できないことを周知する意味もあるので、全員にメール出した方が良さそう。そうなると記事の価値がパアなので続けますワニ🐊

ソースコード

const CALENDAR_ID = '************'; //カレンダーID

function getCalendarEventCreatorList() {
  const calendar = CalendarApp.getCalendarById(CALENDAR_ID); // 検索元カレンダー
  const startDate = new Date('2020/10/01 00:00:00'); // 検索開始日
  const endDate = new Date('2020/11/01 00:00:00'); // 検索終了日

  let creatorName; // イベント作成者
  let creatorList = []; // イベント作成者一覧

  // 開始日から終了日のイベントを取得
  const events = calendar.getEvents(startDate, endDate);

  // イベント数分繰り返す
  for(const event of events){

    // 作成者の取得
    creatorName = event.getCreators()[0];

    // 今までのイベント作成者一覧に登録されていなければ、
    if(creatorList.indexOf(creatorName) === -1){

      // イベント作成者一覧に登録する
      creatorList.push(creatorName);
    }

  }

 // イベント作成者一覧の出力
 console.log(creatorList);
}

注意点

・カレンダーのイベント作成者を取得するので、イベント内容は見ていません。
 例えば、スマホ端末管理カレンダーでNo.10のiPhone利用者だけを抽出というのは、もうひと手間必要になります。

参考にさせて頂いたURL

https://tonari-it.com/gas-calendar-getevents/
https://teratail.com/questions/134118
https://qiita.com/takeharu/items/d75f96f81ff83680013f
https://www.wakuwakubank.com/posts/485-javascript-include-array-string/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0