Office.AppointmentCompose interface
Office.context.mailbox.item の予定開催者モード。
重要: これは内部の Outlook オブジェクトであり、既存のインターフェイスを通じて直接公開されることはありません。 これを Office.context.mailbox.item モードとして扱う必要があります。 詳細については、「 Outlook アイテム オブジェクト モデル」を参照してください。
親インターフェイス:
- Extends
注釈
使用元
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/50-recurrence/get-set-recurrence-appointment-organizer.yaml
// Important: Can only set the recurrence pattern of an appointment series.
const currentDate = new Date();
let seriesTimeObject: Office.SeriesTime;
// Set series start date to tomorrow.
seriesTimeObject.setStartDate(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDay() + 1);
// Set series end date to one year from now.
seriesTimeObject.setEndDate(currentDate.getFullYear() + 1, currentDate.getMonth() + 1, currentDate.getDay());
// Set start time to 1:30 PM.
seriesTimeObject.setStartTime(13, 30);
// Set duration to 30 minutes.
seriesTimeObject.setDuration(30);
const pattern = {
seriesTime: seriesTimeObject,
recurrenceType: Office.MailboxEnums.RecurrenceType.Yearly,
recurrenceProperties: {
interval: 1,
dayOfWeek: Office.MailboxEnums.Days.Tue,
weekNumber: Office.MailboxEnums.WeekNumber.Second,
month: Office.MailboxEnums.Month.Sep
},
recurrenceTimeZone: { name: Office.MailboxEnums.RecurrenceTimeZone.PacificStandardTime }
};
Office.context.mailbox.item.recurrence.setAsync(pattern as any, (asyncResult) => {
if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Failed to set recurrence. Error: ${asyncResult.error.message}`);
return;
}
console.log(`Succeeded in setting recurrence pattern ${JSON.stringify(pattern)}`);
});
プロパティ
| body | アイテムの本文を操作するメソッドを提供するオブジェクトを取得します。 |
| end | 予定が終了する日時を取得または設定します。
重要: Windows クライアントでは、このプロパティを使用して定期的な終了を更新することはできません。 |
| item |
インスタンスが表しているアイテムの種類を取得します。
|
| location | 予定の場所を取得または設定します。
|
| optional |
イベントの任意出席者へのアクセスを提供します。 オブジェクトのタイプとアクセス レベルは、現在の項目のモードによって異なります。
|
| required |
イベントの必須出席者へのアクセスを提供します。 オブジェクトのタイプとアクセス レベルは、現在の項目のモードによって異なります。
|
| start | 予定を開始する日時を取得または設定します。
重要: Windows クライアントでは、このプロパティを使用して繰り返しの開始を更新することはできません。 |
| subject | アイテムの件名フィールドに示される説明を取得または設定します。
|
メソッド
| add |
ファイルを添付ファイルとしてメッセージまたは予定に追加します。
|
| add |
ファイルを添付ファイルとしてメッセージまたは予定に追加します。
|
| add |
メッセージなどの Exchange アイテムを添付ファイルとして、メッセージまたは予定に追加します。
その後、 Office アドインが Windows 上の Outlook on the web と新しい Outlook で実行されている場合、 |
| add |
メッセージなどの Exchange アイテムを添付ファイルとして、メッセージまたは予定に追加します。
その後、 Office アドインが Windows 上の Outlook on the web と新しい Outlook で実行されている場合、 |
| load |
選択されたアイテムのこのアドインのカスタム プロパティを非同期に読み込みます。 カスタム プロパティは、アプリごと、アイテムごとにキーと値のペアとして格納されます。 このメソッドはコールバックで CustomProperties オブジェクトを返します。このオブジェクトには、現在の項目と現在のアドインに固有のカスタム プロパティにアクセスするメソッドが用意されています。 カスタム プロパティはアイテムで暗号化されていないため、これをセキュリティで保護されたストレージとして使用しないでください。 カスタム プロパティは |
| remove |
メッセージまたは予定から添付ファイルを削除します。
|
| remove |
メッセージまたは予定から添付ファイルを削除します。
|
プロパティの詳細
body
アイテムの本文を操作するメソッドを提供するオブジェクトを取得します。
body: Body;
プロパティ値
注釈
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
例
// This example gets the body of the item as plain text.
Office.context.mailbox.item.body.getAsync(
"text",
{ asyncContext: "This is passed to the callback" },
function callback(result) {
// Do something with the result.
});
// The following is an example of an object that is passed as the result parameter to the callback function.
{
"value": "TEXT of whole body (including threads below)",
"status": "succeeded",
"asyncContext": "This is passed to the callback"
}
end
予定が終了する日時を取得または設定します。
end プロパティは、協定世界時 (UTC) の日付と時刻の値として表される Time オブジェクトです。
convertToLocalClientTime メソッドを使用すると、end プロパティ値をクライアントのローカル日付と時刻に変換できます。
Time.setAsync メソッドを使用して終了時刻を設定する場合、convertToUtcClientTime メソッドを使用して、クライアント上のローカルの時刻をサーバーの UTC に変換する必要があります。
重要: Windows クライアントでは、このプロパティを使用して定期的な終了を更新することはできません。
end: Time;
プロパティ値
注釈
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-set-end-appointment-organizer.yaml
Office.context.mailbox.item.end.getAsync((result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Action failed with message ${result.error.message}`);
return;
}
const time = result.value;
const localTime = Office.context.mailbox.convertToLocalClientTime(time);
console.log(`Appointment ends (local): ${localTime.month + 1}/${localTime.date}/${localTime.year}, ${localTime.hours}:${localTime.minutes}:${localTime.seconds}`);
});
...
Office.context.mailbox.item.start.getAsync((result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Get start date failed with message ${result.error.message}`);
return;
}
const end = result.value; // Set end to current start date and time.
end.setDate(end.getDate() + 1); // Set end as 1 day later than start date.
Office.context.mailbox.item.end.setAsync(end, (result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Set end date failed with message ${result.error.message}`);
return;
}
console.log(`Successfully set end date and time to ${end}`);
});
});
itemType
インスタンスが表しているアイテムの種類を取得します。
itemType プロパティは、ItemType 列挙値の 1 つを返します。これは item オブジェクト インスタンスがメッセージと予定のどちらであるかを示すものです。
itemType: MailboxEnums.ItemType | string;
プロパティ値
Office.MailboxEnums.ItemType | string
注釈
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-item-type.yaml
const itemType = Office.context.mailbox.item.itemType;
switch (itemType) {
case Office.MailboxEnums.ItemType.Appointment:
console.log(`Current item is an ${itemType}.`);
break;
case Office.MailboxEnums.ItemType.Message:
console.log(`Current item is a ${itemType}. A message could be an email, meeting request, meeting response, or meeting cancellation.`);
break;
}
location
予定の場所を取得または設定します。
location プロパティは、予定の場所を取得して設定するために使用されるメソッドを提供する Location オブジェクトを返します。
location: Location;
プロパティ値
注釈
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
重要: enhancedLocation プロパティは、メールボックス要件セット 1.8 で導入されました。 特に場所の種類を決定する必要がある場合は、 enhancedLocation プロパティを使用して、予定の場所をより適切に識別および管理します。 シナリオに適した場所 API を選択するガイダンスについては、「Outlook で任命を作成するときに場所を取得または設定する」を参照してください。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-set-location-appointment-organizer.yaml
Office.context.mailbox.item.location.getAsync((result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Action failed with message ${result.error.message}`);
return;
}
console.log(`Appointment location: ${result.value}`);
});
...
const location = "my office";
Office.context.mailbox.item.location.setAsync(location, (result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Action failed with message ${result.error.message}`);
return;
}
console.log(`Successfully set location to ${location}`);
});
optionalAttendees
イベントの任意出席者へのアクセスを提供します。 オブジェクトのタイプとアクセス レベルは、現在の項目のモードによって異なります。
optionalAttendees プロパティは会議への任意出席者を取得または更新するためのメソッドを提供する Recipients オブジェクトを返します。 ただし、クライアント/プラットフォーム (Windows、Mac など) によっては、取得または更新できる受信者の数に制限が適用される場合があります。 詳細については、 Recipients オブジェクトを参照してください。
optionalAttendees: Recipients;
プロパティ値
注釈
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/30-recipients-and-attendees/get-set-optional-attendees-appointment-organizer.yaml
Office.context.mailbox.item.optionalAttendees.getAsync(function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
const apptOptionalAttendees = asyncResult.value;
for (let i = 0; i < apptOptionalAttendees.length; i++) {
console.log(
"Optional attendees: " +
apptOptionalAttendees[i].displayName +
" (" +
apptOptionalAttendees[i].emailAddress +
") - response: " +
apptOptionalAttendees[i].appointmentResponse
);
}
} else {
console.error(asyncResult.error);
}
});
...
const email = (document.getElementById("emailOptional") as HTMLInputElement).value;
const emailArray = [email];
Office.context.mailbox.item.optionalAttendees.setAsync(emailArray, function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
console.log("Succeeded in setting optional attendees field.");
} else {
console.error(asyncResult.error);
}
});
requiredAttendees
イベントの必須出席者へのアクセスを提供します。 オブジェクトのタイプとアクセス レベルは、現在の項目のモードによって異なります。
requiredAttendees プロパティは会議への必須出席者を取得または更新するためのメソッドを提供する Recipients オブジェクトを返します。 ただし、クライアント/プラットフォーム (Windows、Mac など) によっては、取得または更新できる受信者の数に制限が適用される場合があります。 詳細については、 Recipients オブジェクトを参照してください。
requiredAttendees: Recipients;
プロパティ値
注釈
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/30-recipients-and-attendees/get-set-required-attendees-appointment-organizer.yaml
Office.context.mailbox.item.requiredAttendees.getAsync(function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
const apptRequiredAttendees = asyncResult.value;
for (let i = 0; i < apptRequiredAttendees.length; i++) {
console.log(
"Required attendees: " +
apptRequiredAttendees[i].displayName +
" (" +
apptRequiredAttendees[i].emailAddress +
") - response: " +
apptRequiredAttendees[i].appointmentResponse
);
}
} else {
console.error(asyncResult.error);
}
});
...
const email = (document.getElementById("emailRequired") as HTMLInputElement).value;
const emailArray = [email];
Office.context.mailbox.item.requiredAttendees.setAsync(emailArray, function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
console.log("Succeeded in setting required attendees field.");
} else {
console.error(asyncResult.error);
}
});
start
予定を開始する日時を取得または設定します。
start プロパティは、協定世界時 (UTC) の日付と時刻の値として表される Time オブジェクトです。
convertToLocalClientTime メソッドを使用すると、値をクライアントのローカル日付と時刻に変換できます。
Time.setAsync メソッドを使用して開始時刻を設定する場合、convertToUtcClientTime メソッドを使用して、クライアント上のローカルの時刻をサーバーの UTC に変換する必要があります。
重要: Windows クライアントでは、このプロパティを使用して繰り返しの開始を更新することはできません。
start: Time;
プロパティ値
注釈
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-set-start-appointment-organizer.yaml
Office.context.mailbox.item.start.getAsync((result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Action failed with message ${result.error.message}`);
return;
}
const time = result.value;
const localTime = Office.context.mailbox.convertToLocalClientTime(time);
console.log(`Appointment starts (local): ${localTime.month + 1}/${localTime.date}/${localTime.year}, ${localTime.hours}:${localTime.minutes}:${localTime.seconds}`);
});
...
const start = new Date(); // Represents current date and time.
start.setDate(start.getDate() + 2); // Add 2 days to current date.
Office.context.mailbox.item.start.setAsync(start, (result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Action failed with message ${result.error.message}`);
return;
}
console.log(`Successfully set start date and time to ${start}`);
});
subject
アイテムの件名フィールドに示される説明を取得または設定します。
subject プロパティは、電子メール サーバーによって送信されたアイテムの件名全体を取得または設定します。
subject プロパティは件名を取得および設定するためのメソッドを提供する Subject オブジェクトを返します。
subject: Subject;
プロパティ値
注釈
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-set-subject-compose.yaml
Office.context.mailbox.item.subject.getAsync((result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Action failed with message ${result.error.message}`);
return;
}
console.log(`Subject: ${result.value}`);
});
...
let subject = "Hello World!";
Office.context.mailbox.item.subject.setAsync(subject, (result) => {
if (result.status !== Office.AsyncResultStatus.Succeeded) {
console.error(`Action failed with message ${result.error.message}`);
return;
}
console.log(`Successfully set subject to ${subject}`);
});
メソッドの詳細
addFileAttachmentAsync(uri, attachmentName, options, callback)
ファイルを添付ファイルとしてメッセージまたは予定に追加します。
addFileAttachmentAsync メソッドは、指定した URI にあるファイルをアップロードし、新規作成フォーム内のアイテムに添付します。
addFileAttachmentAsync(uri: string, attachmentName: string, options: Office.AsyncContextOptions & { isInline: boolean }, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;
パラメーター
- uri
-
string
メッセージまたは予定に添付するファイルの場所を示す URI。 最大長は 2048 文字です。
- attachmentName
-
string
添付ファイルのアップロード時に表示される添付ファイルの名前。 最大の長さは、255 文字です。
- options
-
Office.AsyncContextOptions & { isInline: boolean }
次のプロパティの 1 つ以上を含むオブジェクト リテラル:- asyncContext: 開発者は、コールバック関数でアクセスしたいオブジェクトを指定できます。
isInline
: true の場合、添付ファイルがメッセージ本文に画像としてインラインで表示され、添付ファイルの一覧には表示されないことを示します。
- callback
-
(asyncResult: Office.AsyncResult<string>) => void
省略可能。 メソッドが完了すると、 callback パラメーターで渡された関数が型 Office.AsyncResult の 1 つのパラメーターで呼び出されます。 成功すると、添付ファイルの識別子が asyncResult.value プロパティに設定されます。 添付ファイルのアップロードに失敗した場合、asyncResult オブジェクトには、エラーの説明を提供する Error オブジェクトが含まれます。
返品
void
注釈
最小アクセス許可レベル: 項目の読み取り/書き込み
適用可能な Outlook モード: 予定の主催者
重要:
この方法は、iOS 版または Android 版 Outlook ではサポートされていません。 Outlook Mobile でサポートされている API の詳細については、「モバイル デバイスの Outlook でサポートされている Outlook JavaScript API」を参照してください。
ビットマップ (BMP) 画像は、インライン添付ファイルとして追加されている場合はサポートされません。
従来の Outlook on Windows の最近のビルドで、このアクションに
Authorization: Bearerヘッダーが誤って付加されるバグが導入されました (この API または Outlook UI を使用する場合)。 この問題を回避するには、要件セット 1.8 で導入されたaddFileAttachmentFromBase64API を使用します。添付するファイルの URI が実稼働環境でのキャッシュをサポートしている必要があります。 画像をホストしているサーバーは、HTTP 応答で
no-cache、no-store、または同様のオプションを指定するCache-Controlヘッダーを返すべきではありません。 ただし、アドインを開発してファイルに変更を加えるときには、キャッシュによって変更が表示されない可能性があります。 開発中はCache-Controlヘッダーを使用することをお勧めします。同じ URI を
removeAttachmentAsyncメソッドで使用して、同じセッションで添付ファイルを削除できます。
エラー:
AttachmentSizeExceeded: 添付ファイルが許可されているサイズより大きくなっています。FileTypeNotSupported: 添付ファイルに、許可されない拡張子があります。NumberOfAttachmentsExceeded: メッセージまたは予定の添付ファイルが多すぎます。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/attachments-compose.yaml
const attachmentUrl = (document.getElementById("attachmentUrl") as HTMLInputElement).value;
Office.context.mailbox.item.addFileAttachmentAsync(
attachmentUrl,
getFileName(attachmentUrl),
{ isInline: false },
(result) => {
if (result.status === Office.AsyncResultStatus.Failed) {
console.log(`Failed to add attachment: ${result.error.message}.`);
return;
}
console.log(`Added attachment with ID: ${result.value}`);
}
);
addFileAttachmentAsync(uri, attachmentName, callback)
ファイルを添付ファイルとしてメッセージまたは予定に追加します。
addFileAttachmentAsync メソッドは、指定した URI にあるファイルをアップロードし、新規作成フォーム内のアイテムに添付します。
addFileAttachmentAsync(uri: string, attachmentName: string, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;
パラメーター
- uri
-
string
メッセージまたは予定に添付するファイルの場所を示す URI。 最大長は 2048 文字です。
- attachmentName
-
string
添付ファイルのアップロード時に表示される添付ファイルの名前。 最大の長さは、255 文字です。
- callback
-
(asyncResult: Office.AsyncResult<string>) => void
省略可能。 メソッドが完了すると、 callback パラメーターで渡された関数が型 Office.AsyncResult の 1 つのパラメーターで呼び出されます。 成功すると、添付ファイルの識別子が asyncResult.value プロパティに設定されます。 添付ファイルのアップロードに失敗した場合、asyncResult オブジェクトには、エラーの説明を提供する Error オブジェクトが含まれます。
返品
void
注釈
最小アクセス許可レベル: 項目の読み取り/書き込み
適用可能な Outlook モード: 予定の主催者
重要:
この方法は、iOS 版または Android 版 Outlook ではサポートされていません。 Outlook Mobile でサポートされている API の詳細については、「モバイル デバイスの Outlook でサポートされている Outlook JavaScript API」を参照してください。
ビットマップ (BMP) 画像は、インライン添付ファイルとして追加されている場合はサポートされません。
従来の Outlook on Windows の最近のビルドで、このアクションに
Authorization: Bearerヘッダーが誤って付加されるバグが導入されました (この API または Outlook UI を使用する場合)。 この問題を回避するには、要件セット 1.8 で導入されたaddFileAttachmentFromBase64API を使用します。添付するファイルの URI が実稼働環境でのキャッシュをサポートしている必要があります。 画像をホストしているサーバーは、HTTP 応答で
no-cache、no-store、または同様のオプションを指定するCache-Controlヘッダーを返すべきではありません。 ただし、アドインを開発してファイルに変更を加えるときには、キャッシュによって変更が表示されない可能性があります。 開発中はCache-Controlヘッダーを使用することをお勧めします。同じ URI を
removeAttachmentAsyncメソッドで使用して、同じセッションで添付ファイルを削除できます。
エラー:
AttachmentSizeExceeded: 添付ファイルが許可されているサイズより大きくなっています。FileTypeNotSupported: 添付ファイルに、許可されない拡張子があります。NumberOfAttachmentsExceeded: メッセージまたは予定の添付ファイルが多すぎます。
addItemAttachmentAsync(itemId, attachmentName, options, callback)
メッセージなどの Exchange アイテムを添付ファイルとして、メッセージまたは予定に追加します。
addItemAttachmentAsync メソッドは、指定された Exchange 識別子を持つアイテムを作成フォーム内のアイテムに添付します。 コールバック関数を指定すると、メソッドは 1 つのパラメーター ( asyncResult) を使用して呼び出されます。このパラメーターには、添付ファイル識別子またはアイテムの添付中に発生したエラーを示すコードが含まれます。 必要に応じて、 options パラメーターを使用して、状態情報をコールバック関数に渡すことができます。
その後、removeAttachmentAsync メソッドで識別子を使用して同じセッションの添付ファイルを削除できます。
Office アドインが Windows 上の Outlook on the web と新しい Outlook で実行されている場合、addItemAttachmentAsync メソッドでは、編集中のアイテム以外のアイテムにアイテムを添付できます。 ただし、これはサポートされておらず、推奨されません。
addItemAttachmentAsync(itemId: any, attachmentName: string, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;
パラメーター
- itemId
-
any
添付するアイテムの Exchange 識別子。 最大長は 100 文字です。
- attachmentName
-
string
添付ファイルのアップロード時に表示される添付ファイルの名前。 最大の長さは、255 文字です。
- options
- Office.AsyncContextOptions
次のプロパティの 1 つ以上を含むオブジェクト リテラル:- asyncContext: 開発者は、コールバック関数でアクセスしたいオブジェクトを指定できます。
- callback
-
(asyncResult: Office.AsyncResult<string>) => void
省略可能。 メソッドが完了すると、コールバック パラメーターに渡された関数は、型 Office.AsyncResult の 1 つのパラメーターで呼び出されます。 成功すると、添付ファイルの識別子が asyncResult.value プロパティに設定されます。 添付ファイルの追加に失敗した場合、asyncResult オブジェクトには、エラーの説明を提供する Error オブジェクトが含まれます。
返品
void
注釈
最小アクセス許可レベル: 項目の読み取り/書き込み
適用可能な Outlook モード: 予定の主催者
エラー:
-
NumberOfAttachmentsExceeded: メッセージまたは予定の添付ファイルが多すぎます。
例
// The following example adds an existing Outlook item as an attachment
// with the name "My Attachment".
function addAttachment() {
// EWS ID of item to attach (shortened for readability).
const itemId = "AAMkADI1...AAA=";
// The values in asyncContext can be accessed in the callback.
const options = { asyncContext: { var1: 1, var2: 2 } };
Office.context.mailbox.item.addItemAttachmentAsync(itemId, "My Attachment", options, (result) => {
if (result.status === Office.AsyncResultStatus.Failed) {
console.error("Failed to add attachment: " + result.error.message);
return;
}
console.log("Attachment added successfully.");
console.log("var1: " + result.asyncContext.var1);
console.log("var2: " + result.asyncContext.var2);
});
}
addItemAttachmentAsync(itemId, attachmentName, callback)
メッセージなどの Exchange アイテムを添付ファイルとして、メッセージまたは予定に追加します。
addItemAttachmentAsync メソッドは、指定された Exchange 識別子を持つアイテムを作成フォーム内のアイテムに添付します。 コールバック関数を指定すると、メソッドは 1 つのパラメーター ( asyncResult) を使用して呼び出されます。このパラメーターには、添付ファイル識別子またはアイテムの添付中に発生したエラーを示すコードが含まれます。 必要に応じて、 options パラメーターを使用して、状態情報をコールバック関数に渡すことができます。
その後、removeAttachmentAsync メソッドで識別子を使用して同じセッションの添付ファイルを削除できます。
Office アドインが Windows 上の Outlook on the web と新しい Outlook で実行されている場合、addItemAttachmentAsync メソッドでは、編集中のアイテム以外のアイテムにアイテムを添付できます。 ただし、これはサポートされておらず、推奨されません。
addItemAttachmentAsync(itemId: any, attachmentName: string, callback?: (asyncResult: Office.AsyncResult<string>) => void): void;
パラメーター
- itemId
-
any
添付するアイテムの Exchange 識別子。 最大長は 100 文字です。
- attachmentName
-
string
添付ファイルのアップロード時に表示される添付ファイルの名前。 最大の長さは、255 文字です。
- callback
-
(asyncResult: Office.AsyncResult<string>) => void
省略可能。 メソッドが完了すると、コールバック パラメーターに渡された関数は、型 Office.AsyncResult の 1 つのパラメーターで呼び出されます。 成功すると、添付ファイルの識別子が asyncResult.value プロパティに設定されます。 添付ファイルの追加に失敗した場合、asyncResult オブジェクトには、エラーの説明を提供する Error オブジェクトが含まれます。
返品
void
注釈
最小アクセス許可レベル: 項目の読み取り/書き込み
適用可能な Outlook モード: 予定の主催者
エラー:
-
NumberOfAttachmentsExceeded: メッセージまたは予定の添付ファイルが多すぎます。
loadCustomPropertiesAsync(callback, userContext)
選択されたアイテムのこのアドインのカスタム プロパティを非同期に読み込みます。
カスタム プロパティは、アプリごと、アイテムごとにキーと値のペアとして格納されます。 このメソッドはコールバックで CustomProperties オブジェクトを返します。このオブジェクトには、現在の項目と現在のアドインに固有のカスタム プロパティにアクセスするメソッドが用意されています。 カスタム プロパティはアイテムで暗号化されていないため、これをセキュリティで保護されたストレージとして使用しないでください。
カスタム プロパティは asyncResult.value プロパティの CustomProperties オブジェクトとして指定されます。 このオブジェクトを使用して、メール アイテムからカスタム プロパティを取得、設定、保存、および削除できます。
loadCustomPropertiesAsync(callback: (asyncResult: Office.AsyncResult<CustomProperties>) => void, userContext?: any): void;
パラメーター
- callback
-
(asyncResult: Office.AsyncResult<Office.CustomProperties>) => void
メソッドが完了すると、 callback パラメーターで渡された関数が型 Office.AsyncResult の 1 つのパラメーターで呼び出されます。
- userContext
-
any
省略可能。 開発者は、コールバック関数でアクセスする任意のオブジェクトを指定できます。 このオブジェクトには、コールバック関数の asyncResult.asyncContext プロパティによってアクセスすることができます。
返品
void
注釈
カスタム プロパティの詳細については、「Outlook アドインのアドイン メタデータを取得して設定する」を参照してください。
最小アクセス許可レベル: 項目の読み取り
適用可能な Outlook モード: 予定の主催者
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/15-item-custom-properties/load-set-get-save.yaml
Office.context.mailbox.item.loadCustomPropertiesAsync((result) => {
if (result.status === Office.AsyncResultStatus.Failed) {
console.error(`loadCustomPropertiesAsync failed with message ${result.error.message}`);
return;
}
customProps = result.value;
console.log("Loaded the CustomProperties object.");
});
removeAttachmentAsync(attachmentId, options, callback)
メッセージまたは予定から添付ファイルを削除します。
removeAttachmentAsync メソッドは、指定した識別子の添付ファイルをアイテムから削除します。 ベスト プラクティスとして、同じメール アプリが同じセッションで添付ファイルを追加した場合にのみ、その添付ファイルの識別子を使用して添付ファイルを削除することをお勧めします。 Outlook on the web、モバイル デバイス、および新しい Outlook on Windows では、添付ファイル識別子は同じセッション内でのみ有効です。 ユーザーがアプリを閉じるか、ユーザーがインライン フォームの作成を開始した後、フォームをポップアウトして別のウィンドウで続行すると、セッションは終了です。
removeAttachmentAsync(attachmentId: string, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;
パラメーター
- attachmentId
-
string
削除する添付ファイルの識別子。
attachmentIdの最大の文字列長は、Outlook on the web および Windows (新旧) で 200 文字です。
- options
- Office.AsyncContextOptions
次のプロパティの 1 つ以上を含むオブジェクト リテラル:- asyncContext: 開発者は、コールバック関数でアクセスしたいオブジェクトを指定できます。
- callback
-
(asyncResult: Office.AsyncResult<void>) => void
省略可能。 メソッドが完了すると、 callback パラメーターで渡された関数が型 Office.AsyncResult の 1 つのパラメーターで呼び出されます。 添付ファイルの削除に失敗すると、asyncResult.error プロパティにはエラー コードとエラーの理由が含まれます。
返品
void
注釈
最小アクセス許可レベル: 項目の読み取り/書き込み
適用可能な Outlook モード: 予定の主催者
重要: removeAttachmentAsync メソッドでは、メール アイテムからインライン添付ファイルは削除されません。 インライン添付ファイルを削除するには、まずアイテムの本文を取得してから、そのコンテンツから添付ファイルの参照をすべて削除します。
Office.Body API を使用して、項目の本文を取得して設定します。
エラー:
-
InvalidAttachmentId: 添付ファイル識別子は存在しません。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/40-attachments/attachments-compose.yaml
Office.context.mailbox.item.removeAttachmentAsync(
(document.getElementById("attachmentId") as HTMLInputElement).value,
(result) => {
if (result.status === Office.AsyncResultStatus.Failed) {
console.error(result.error.message);
return;
}
console.log(`Attachment removed successfully.`);
}
);
removeAttachmentAsync(attachmentId, callback)
メッセージまたは予定から添付ファイルを削除します。
removeAttachmentAsync メソッドは、指定した識別子の添付ファイルをアイテムから削除します。 ベスト プラクティスとして、同じメール アプリが同じセッションで添付ファイルを追加した場合にのみ、その添付ファイルの識別子を使用して添付ファイルを削除することをお勧めします。 Outlook on the web、モバイル デバイス、および新しい Outlook on Windows では、添付ファイル識別子は同じセッション内でのみ有効です。 ユーザーがアプリを閉じるか、ユーザーがインライン フォームの作成を開始した後、フォームをポップアウトして別のウィンドウで続行すると、セッションは終了です。
removeAttachmentAsync(attachmentId: string, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;
パラメーター
- attachmentId
-
string
削除する添付ファイルの識別子。
attachmentIdの最大の文字列長は、Outlook on the web および Windows (新旧) で 200 文字です。
- callback
-
(asyncResult: Office.AsyncResult<void>) => void
省略可能。 メソッドが完了すると、 callback パラメーターで渡された関数が型 Office.AsyncResult の 1 つのパラメーターで呼び出されます。 添付ファイルの削除に失敗すると、asyncResult.error プロパティにはエラー コードとエラーの理由が含まれます。
返品
void
注釈
最小アクセス許可レベル: 項目の読み取り/書き込み
適用可能な Outlook モード: 予定の主催者
重要: removeAttachmentAsync メソッドでは、メール アイテムからインライン添付ファイルは削除されません。 インライン添付ファイルを削除するには、まずアイテムの本文を取得してから、そのコンテンツから添付ファイルの参照をすべて削除します。
Office.Body API を使用して、項目の本文を取得して設定します。
エラー:
-
InvalidAttachmentId: 添付ファイル識別子は存在しません。