
【GAS】Google Apps Script 活用事例 イベントIDから面談予定時刻と終了時刻を取得するスクリプト
本記事では、Google Apps Scriptを用いて、イベントIDから開始時刻と終了時刻を取得する方法をご紹介します。
イベントIDとは
イベントIDとは、予定を登録する際に割り当てられる英数字の羅列です。スクリプトで登録した際に転記しておくと便利です。イベントIDは、日程を後から変更を加えても不変です。

ライブラリを一部使っています。
スクリプトID
18rg2maFYXNmPmB2R-8s3UuFG850j5OLw4WBvcOrghzRMlfVbQWDgOVvZ


/**
* イベントiDを元に取得した開始時刻と終了時刻をスプレッドシートに転記する
*
*/
function myFunction(){
const sheet = SpreadsheetApp.getActiveSheet();
const values = sheet.getDataRange().getValues();
values.shift();
let newValues = [];
for(let i = 0; i < values.length; i ++){
const eventId = values[i][4];
console.log(eventId);
newValues.push([getCalEvent_(eventId)]);
}
sheet.getRange(2, 7, newValues.length, newValues[0].length).setValues(newValues);
}
/**
* イベントiDから予定の開始日時と終了日時を取得する
*
*/
function getCalEvent_(eventId) {
const calId = '**************';
const cal = CalendarApp.getCalendarById(calId);
const event = cal.getEventById(eventId);
//ライブラリの一部の機能を使用しています。
const startTime = nepia_infinity.formatDate(event.getStartTime(), 'yyyy/MM/dd (E) HH:mm');
const endTime = nepia_infinity.formatDate(event.getEndTime(), 'HH:mm');
const merged = `${startTime} - ${endTime}`;
console.log(merged);
return merged
}