Outlook 予定表のイベント作成 (Outlook Calendar Event Insert)
Outlook 予定表にイベントを作成します。
Configs
  • A: OAuth2 設定 *
  • B: イベント名 *
  • C: イベント詳細説明 *
  • D: イベント実施場所 *
  • E: イベントの開始日時 *
  • F: イベントの終了日時 *
  • G: イベントの日時のタイムゾーン(例:Tokyo Standard Time) *
  • H: イベント参加者のメールアドレスリスト(カンマ区切り) *
  • I: イベント任意参加者のメールアドレスリスト(カンマ区切り)
  • J: オンラインミーティングありか
  • K: 通知メールをHTML形式にするか
  • O: イベントIDを保存するデータ項目 (更新)
  • P: イベントURLを保存するデータ項目 (更新)
  • Q: オンラインミーティングのURLを保存するデータ項目 (更新)
  • X: 通信ログを保存するデータ項目 (更新)
Script (click to open)


// Insert Outlook Calendar Event via Microsoft Graph API v1.0 (ver. 202209)
// (c) 2022, Questetra, Inc. (the MIT License)

//// == 工程コンフィグの参照 / Config Retrieving ==
const oauth2  = configs.get( "conf_OAuth2" ) + "";

const subject         = engine.findDataByNumber( configs.get( "conf_subject" ) ) + "";
const content         = engine.findDataByNumber( configs.get( "conf_discription" ) ) + "";
const location        = engine.findDataByNumber( configs.get( "conf_location" ) ) + "";
const startDate       = engine.findDataByNumber( configs.get( "conf_startDate" ) ) + "";
const endDate         = engine.findDataByNumber( configs.get( "conf_endDate" ) ) + "";
const timeZone        = configs.get( "conf_timeZone" ) + "";

const attendeesList   = engine.findDataByNumber( configs.get( "conf_attendees" ) ) + "";

const dataId_attendeesOptionalList = configs.get( "conf_attendeesOptional" );

const isOnlineMeeting = configs.getObject( "conf_isOnlineMeeting" );
const isHtmlMail      = configs.getObject( "conf_isHtmlMail" );

const dataId_eventId          = configs.get( "conf_eventId" );
const dataId_eventUrl         = configs.get( "conf_eventUrl" );
const dataId_onlineMeetingUrl = configs.get( "conf_onlineMeetingUrl" );
const dataId_log              = configs.get( "conf_log" );


//// == 演算 / Calculating ==
if ( attendeesList == "null" ) {
  throw `attendeesList none.`;
}

let requestObj = {};
  requestObj.subject = subject;
  //未指定の場合を考慮
  if ( content !== "null" ) {
    requestObj.body = {};
    requestObj.body.content = content;
  }
  requestObj.start = {};
  requestObj.start.dateTime = startDate;
  requestObj.start.timeZone = timeZone;
  requestObj.end = {};
  requestObj.end.dateTime = endDate;
  requestObj.end.timeZone = timeZone;
  //未指定の場合を考慮
  if ( location !== "null" ) {
    requestObj.location = {};
    requestObj.location.displayName = location;
  }

  let attendees = new Array();
  attendees = attendeesList.split(",");
  requestObj.attendees = [];
  for (let i = 0; i < attendees.length; i++) {
    let attendee = attendees[i];
    requestObj.attendees[i] = {};
    requestObj.attendees[i].emailAddress = {};
    requestObj.attendees[i].emailAddress.address = attendee;
  }

  if ( dataId_attendeesOptionalList !== "" ) {
    const attendeesLength = attendees.length;

    const attendeesOptionalList = engine.findDataByNumber( dataId_attendeesOptionalList ) + "";
    if ( attendeesOptionalList !== "null" ) {
      let attendeesOptional = new Array();
      attendeesOptional = attendeesOptionalList.split(",");
      const attendeesTotalLength = attendeesLength + attendeesOptional.length;
      for (let i = 0; i < attendeesOptional.length; i++) {
        let attendeeOptional = attendeesOptional[i];
        requestObj.attendees[i + attendeesLength] = {};
        requestObj.attendees[i + attendeesLength].emailAddress = {};
        requestObj.attendees[i + attendeesLength].emailAddress.address = attendeeOptional;
        requestObj.attendees[i + attendeesLength].type = "optional";
      }
    }
  }

  requestObj.isOnlineMeeting = isOnlineMeeting;

  if ( isHtmlMail ) {
    requestObj.body.contentType = "html"
  }

engine.log("json:" + JSON.stringify( requestObj ));

let accessLog = "";
let uri = "https://graph.microsoft.com/v1.0/me/events";
let response = httpClient.begin()
  .authSetting( oauth2 )
  .body( JSON.stringify( requestObj ), "application/json" )
  .post( uri );
accessLog += "---POST request--- " + response.getStatusCode() + "\n";
accessLog += response.getResponseAsString() + "\n";


//// == ワークフローデータへの代入 / Data Updating ==
var status = response.getStatusCode();

if( status >= 300 ){
  engine.log(accessLog);
  throw `Failed in POST request. status: ${status}`;
} else {
  const jsonObj = JSON.parse( response.getResponseAsString() );
  const eventId = jsonObj.id + "";
  const eventUrl = jsonObj.webLink + "";
  const onlineMeetingUrl = jsonObj.onlineMeeting.joinUrl + "";

  if( dataId_eventId !== "" ){
    engine.setDataByNumber( dataId_eventId, eventId );
  }
  if( dataId_eventUrl !== "" ){
    engine.setDataByNumber( dataId_eventUrl, eventUrl );
  }
  if( dataId_onlineMeetingUrl !== "" ){
    engine.setDataByNumber( dataId_onlineMeetingUrl, onlineMeetingUrl );
  }
}

if( dataId_log !== "" ){
  engine.setDataByNumber( dataId_log, accessLog );
}

Download

2022-09-14 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/outlook-calendar-event-insert/
Addonファイルのインポートは Professional でのみご利用いただけます
自由改変可能な JavaScript (ECMAScript) コードです。いかなる保証もありません。

Notes

Capture

See also

%d人のブロガーが「いいね」をつけました。