Google カレンダー: 予定追加

Google カレンダー: 予定追加

Google Calendar: Insert Event

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

Auto Step icon
Basic Configs
工程名
メモ
Configs for this Auto Step
conf_User
C1: Google カレンダー に接続するユーザ(要アプリ管理権限) *
conf_DataIdB
C2: Calendar ID (空白の場合プライマリのカレンダーに追加されます)
conf_DataIdC
C3: 予定タイトル *#{EL}
conf_DataIdD
C4: 開始時刻が格納されているデータ項目 *
conf_DataIdE
C5: 終了時刻が格納されているデータ項目 (未設定の場合、+1:00)
conf_DataIdF
C6: 場所#{EL}
conf_DataIdG
C7: 説明#{EL}
conf_eventId
C8: 予定 ID を保存するデータ項目
conf_eventUrl
C9: 予定 URL を保存するデータ項目
conf_meetUrl
C10: Google Meet の URL を保存するデータ項目

Notes

  • C1 のユーザは、[アカウント設定]>[Google 連携]にて、Google カレンダーと連携済みである必要があります
    • ワークフロー基盤にて、Google 連携設定([システム設定]>[Google 連携])が必要です(要[システム管理権限])
  • カレンダーIDは次のページを参照します。[カレンダー設定](Calendar Settings)>[カレンダーのアドレス](Calendar Address)
  • 開始時刻と終了時刻を持つ予定(イベント)が追加されます (”終日予定” は追加できません)
  • 終了時刻のデータ項目が無い場合や終了時刻が未入力状態の場合、開始時刻+60分がセットされます
  • 終了時刻が開始時刻よりも過去となるような予定は、カレンダー追加されません

Capture

See also

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

function main() {
    //// == 工程コンフィグの参照 / Config Retrieving ==
    const quser = configs.getObject("conf_User");
    if (quser === null) {
        throw `User not found.`;
    }
    let calendarId = configs.get("conf_DataIdB");
    if (calendarId === "" || calendarId === null) {
        calendarId = "primary";
    }
    const eventSummary = configs.get("conf_DataIdC");
    if (eventSummary === "" || eventSummary === null) {
        throw "Event Title is blank.";
    }
    const startDate = engine.findData(configs.getObject("conf_DataIdD"));
    if (startDate === null) {
        throw "Event Start Date is blank.";
    }
    const endDateDef = configs.getObject("conf_DataIdE");
    let endDate = null;
    if (endDateDef !== null) {
        endDate = engine.findData(endDateDef);
    }
    let eventLocation = configs.get("conf_DataIdF");
    if (eventLocation === null) {
        eventLocation = "";
    }
    let eventDescription = configs.get("conf_DataIdG");
    if (eventDescription === null) {
        eventDescription = "";
    }

    const eventIdDataDef = configs.getObject("conf_eventId");
    const eventUrlDataDef = configs.getObject("conf_eventUrl");
    const meetUrlDataDef = configs.getObject("conf_meetUrl");

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

    if (endDate === null) {
        endDate = startDate.addHours(1);
    }
    if (endDate.getTime() < startDate.getTime()) {
        throw "Event End Date comes before Event Start Date.";
    }

    //// == 予定を追加する / Insert Event ==
    insertEvent(
        quser,
        calendarId,
        eventSummary,
        eventLocation,
        eventDescription,
        startDate,
        endDate,
        eventIdDataDef,
        eventUrlDataDef,
        meetUrlDataDef
    );
}

/**
 * Google カレンダーにイベントを追加する
 * @param {QuserView} quser ユーザー
 * @param {String} calendarId カレンダーID
 * @param {String} eventSummary 予定タイトル
 * @param {String} eventLocation 場所情報
 * @param {String} eventDescription 説明情報
 * @param {AddableTimestamp} startDate 開始日時
 * @param {AddableTimestamp} endDate 終了日時
 * @param {ProcessDataDefinitionView} eventIdDataDef Event ID を保存する文字型データ項目
 * @param {ProcessDataDefinitionView} eventUrlDataDef Event URL を保存する文字型データ項目
 * @param {ProcessDataDefinitionView} meetUrlDataDef Meet URL を保存する文字型データ項目
 */
function insertEvent(
    quser,
    calendarId,
    eventSummary,
    eventLocation,
    eventDescription,
    startDate,
    endDate,
    eventIdDataDef,
    eventUrlDataDef,
    meetUrlDataDef
) {
    const uri = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events`;

    const sdf = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

    const myObj = {};
    myObj.summary = eventSummary;
    myObj.location = eventLocation;
    myObj.description = eventDescription;
    myObj.start = {};
    myObj.start.dateTime = sdf.format(startDate);
    myObj.start.timeZone = engine.getTimeZoneId();
    myObj.end = {};
    myObj.end.dateTime = sdf.format(endDate);
    myObj.end.timeZone = engine.getTimeZoneId();
    myObj.source = {};
    myObj.conferenceData = {};
    myObj.conferenceData.createRequest = {};
    myObj.conferenceData.createRequest.requestId = `q-${processInstance.getProcessInstanceId()}`;
    myObj.conferenceData.createRequest.conferenceSolutionKey = {};
    myObj.conferenceData.createRequest.conferenceSolutionKey.type =
        "hangoutsMeet";

    let request = httpClient.begin().googleOAuth2(quser, "Calendar");
    if (meetUrlDataDef !== null) {
        request = request.queryParam("conferenceDataVersion", "1");
    }
    const response = request
        .body(JSON.stringify(myObj), "application/json")
        .post(uri);

    const status = response.getStatusCode();
    if (status >= 300) {
        const accessLog = `---POST request---${status}\n${response.getResponseAsString()}`;
        engine.log(accessLog);
        throw `Failed to insert event. status:${status}`;
    }

    const responseStr = response.getResponseAsString();
    const eventJson = JSON.parse(responseStr);
    const eventId = eventJson.id;
    const eventUrl = eventJson.htmlLink;
    const meetUrl = eventJson.hangoutLink;
    if (eventIdDataDef !== null) {
        engine.setData(eventIdDataDef, eventId);
    }
    if (eventUrlDataDef !== null) {
        engine.setData(eventUrlDataDef, eventUrl);
    }
    if (meetUrlDataDef !== null) {
        engine.setData(meetUrlDataDef, meetUrl);
    }
}

Questetra Supportをもっと見る

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

続きを読む

上部へスクロール