Google カレンダー: 予定のカレンダー移動

Google カレンダー: 予定のカレンダー移動

Google Calendar: Move Event to another Calendar

この工程は、Google カレンダーの予定を別のカレンダーに移動します。

Auto Step icon
Basic Configs
工程名
メモ
Configs for this Auto Step
conf_User
C1: Google カレンダー に接続するユーザ(要アプリ管理権限) *
conf_CalendarId
C2: 予定の移動元カレンダー ID (空白の場合、プライマリのカレンダー)
conf_Destination
C3: 予定の移動先カレンダー ID (空白の場合、プライマリのカレンダー)
conf_EventId
C4: 予定 ID *
conf_htmlLink
C5: 予定 URL を保存するデータ項目

Notes

  1. C1 のユーザは、[アカウント設定]>[Google 連携]にて、Google カレンダーと連携済みである必要があります
    • ワークフロー基盤にて、Google 連携設定([システム設定]>[Google 連携])が必要です(要[システム管理権限])
  2. カレンダー ID は次のページを参照します。[カレンダー設定](Calendar Settings)>[カレンダーのアドレス](Calendar Address)
  3. 予定 ID はカレンダー画面からは取得できません。開始: Google カレンダー: 予定開始時などで取得したものを使用してください。

Capture

See also

Script (click to open)
  • 次のスクリプトが記述されている XML ファイルをダウンロードできます
    • google-calendar-event-move.xml (C) Questetra, Inc. (MIT License)
    • Professional のワークフロー基盤では、ファイル内容を改変しオリジナルのアドオン自動工程として活用できます


function main() {
    //// == 工程コンフィグの参照 / Config Retrieving ==
    const quser = configs.getObject("conf_User");
    if (quser === null) {
        throw `User not found.`;
    }
    const calendarId = getCalendarId("conf_CalendarId");
    const destination = getCalendarId("conf_Destination");

    const eventId = engine.findData(configs.getObject("conf_EventId"));
    if (eventId === "" || eventId === null) {
        throw "Event ID isn't set.";
    }

    const htmlLinkDataDef = configs.getObject("conf_htmlLink");

    const calIdRegex = /^[\w\-_.!*'@]+$/;
    
    //// == 演算 / Calculating ==
    if (destination.search(calIdRegex) === -1) {
        throw "Invalid Destination Calendar ID.";
    }

    if (calendarId.search(calIdRegex) === -1) {
        throw "Invalid Source Calendar ID.";
    }

    moveEvent(quser, calendarId, eventId, destination);
    getHtmlLink(quser, destination, eventId, htmlLinkDataDef);
}

/**
 * configs から カレンダー ID を取得する
 * @param confName 設定名
 * @returns {string} カレンダー ID
 */
function getCalendarId(confName) {
    let calendarId = configs.get(confName);
    if (calendarId === "" || calendarId === null) {
        return "primary";
    }
    return calendarId;
}

/**
 * Google カレンダーのイベントを別のカレンダーに移動する
 * @param {QuserView} quser ユーザー
 * @param {String} calendarId カレンダーID
 * @param {String} eventId 予定ID
 * @param {String} destination 移動先カレンダーID
 */
function moveEvent(quser, calendarId, eventId, destination) {

    const uri = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/${eventId}/move`;

    const myObj = {};
    myObj.destination = destination;

    const response = httpClient.begin()
        .googleOAuth2(quser, "Calendar")
        .body(JSON.stringify(myObj), "application/json")
        .post(uri);

    const status = response.getStatusCode();
    const responseStr = response.getResponseAsString();
    engine.log(`Event ID: ${eventId}`);
    if (status >= 300) {
        engine.log(`Status: ${status}`);
        engine.log(responseStr);
        throw `Failed to move.`;
    }
    engine.log('Succeeded to move.');
}

/**
 * イベントを再取得し、HTML Link を保存する
 * @param quser
 * @param calendarId
 * @param eventId
 * @param htmlLinkDataDef
 */
function getHtmlLink(quser, calendarId, eventId, htmlLinkDataDef) {
    if (htmlLinkDataDef === null) {
        return;
    }
    const uri = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/${eventId}`;

    const response = httpClient.begin()
        .googleOAuth2(quser, "Calendar")
        .get(uri);

    const status = response.getStatusCode();
    const responseStr = response.getResponseAsString();
    if (status >= 300) {
        engine.log(`Status: ${status}`);
        engine.log(responseStr);
        throw `Failed to get htmlLink.`;
    }
    const respJson = JSON.parse(responseStr);
    const htmlLink = respJson['htmlLink'];
    engine.setData(htmlLinkDataDef, htmlLink);
    engine.log("Succeeded to get htmlLink");
}

Questetra Supportをもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

上部へスクロール