0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AAAJIsじゃおあs

Posted at
function manageMeetingRoomsEfficiently() {
  // 3週間後の日時を取得
  const now = new Date();
  const threeWeeksLater = new Date(now.getTime() + 3 * 7 * 24 * 60 * 60 * 1000);

  // 会議室のメールアドレスリスト
  const rooms = ['room1@example.com', 'room2@example.com', 'room3@example.com'];

  for (let i = 0; i < rooms.length; i++) {
    const room = rooms[i];

    // 3週間分の予定をroomごとに取得
    const events = CalendarApp.getDefaultCalendar().getEvents(now, threeWeeksLater);

    // まず、該当する会議室が既に追加されているイベントをフィルタリング
    let eventsToProcess = events.filter(function(event) {
      const attendees = event.getGuests();
      let isRoomAdded = false;

      attendees.forEach(function(guest) {
        if (guest.getEmail() === room && guest.getStatus() === "ACCEPTED") {
          isRoomAdded = true;
        }
      });

      return !isRoomAdded;
    });

    // Declineされている会議室を削除
    eventsToProcess.forEach(function(event) {
      const attendees = event.getGuests();
      attendees.forEach(function(guest) {
        if (guest.getEmail() === room && guest.getStatus() === "DECLINED") {
          event.removeGuest(room);
        }
      });
    });

    // まだ会議室が追加されていないイベントに対して、現在のroomを追加
    eventsToProcess.forEach(function(event) {
      event.addGuest(room);
    });

    // 10秒待機
    Utilities.sleep(10000);
  }
}

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?