Office.AsyncResult interface
要求が失敗した場合の状態やエラー情報など、非同期要求の結果をカプセル化するオブジェクト。
"Async" メソッドの callback パラメーターに渡す関数が実行されると、 callback 関数の唯一のパラメーターからアクセスできる AsyncResult オブジェクトを受け取ります。
注釈
使用元
- Office: を選択します。
- Office.AppointmentCompose: addFileAttachmentAsync, addFileAttachmentFromBase64Async, addHandlerAsync, addItemAttachmentAsync, disableClientSignatureAsync, getAttachmentContentAsync, getAttachmentsAsync, getInitializationContextAsync, getItemIdAsync, getSelectedDataAsync, getSharedPropertiesAsync, isClientSignatureEnableDsync, loadCustomPropertiesAsync, removeAttachmentAsync, removeHandlerAsync, saveAsync, sendAsync, setSelectedDataAsync
- Office.AppointmentRead: addHandlerAsync、 displayReplyAllFormAsync、 displayReplyFormAsync、 getAttachmentContentAsync、 getInitializationContextAsync、 getSharedPropertiesAsync、 loadCustomPropertiesAsync、 removeHandlerAsync
- Office.Auth: getAccessTokenAsync
- Office.Binding: addHandlerAsync、 getDataAsync、 removeHandlerAsync、 setDataAsync
- Office.Bindings: addFromNamedItemAsync、 addFromPromptAsync、 addFromSelectionAsync、 getAllAsync、 getByIdAsync、 releaseByIdAsync
- Office.Body: appendOnSendAsync、 getAsync、 getTypeAsync、 prependAsync、 prependOnSendAsync、 setAsync、 setSelectedDataAsync、 setSignatureAsync
- Office.Categories: addAsync, getAsync, removeAsync
- Office.CustomProperties: saveAsync
- Office.CustomXmlNode: getNodesAsync、 getNodeValueAsync、 getTextAsync、 getXmlAsync、 setNodeValueAsync、 setTextAsync、 setXmlAsync
- Office.CustomXmlPart: addHandlerAsync、 deleteAsync、 getNodesAsync、 getXmlAsync、 removeHandlerAsync
- Office.CustomXmlParts: addAsync、 getByIdAsync、 getByNamespaceAsync
- Office.CustomXmlPrefixMappings: addNamespaceAsync, getNamespaceAsync, getPrefixAsync
- Office.DelayDeliveryTime: getAsync, setAsync
- Office.DevicePermission: requestPermissionsAsync
- Office.DisplayedBody: setAsync
- Office.DisplayedSubject: setAsync
- Office.Document: addHandlerAsync、 getActiveViewAsync、 getFileAsync、 getFilePropertiesAsync、 getMaxResourceIndexAsync、 getMaxTaskIndexAsync、 getProjectFieldAsync、 getResourceByIndexAsync、 getResourceFieldAsync、 getSelectedDataAsync、 getSelectedResourceAsync、 getSelectedTaskAsync、 getSelectedViewAsync、 getTaskAsync、getTaskAsync、 getTaskByIndexAsync、 getTaskFieldAsync、 getWSSUrlAsync、 goToByIdAsync、 removeHandlerAsync、 setResourceFieldAsync、 setSelectedDataAsync、 setTaskFieldAsync
- Office.EnhancedLocation: addAsync, getAsync, removeAsync
- Office.Ews: getTokenStatusAsync
- Office.File: closeAsync, getSliceAsync
- Office.From: getAsync
- Office.InternetHeaders: getAsync、 removeAsync、 setAsync
- Office.IsAllDayEvent: getAsync、 setAsync
- Office.LoadedMessageCompose: getAttachmentContentAsync、 getAttachmentsAsync、 getComposeTypeAsync、 getConversationIndexAsync、 getInitializationContextAsync、 getItemClassAsync、 getItemIdAsync、 getSharedPropertiesAsync、 isClientSignatureEnabledAsync、 loadCustomPropertiesAsync、 saveAsync、 unloadAsync
- Office.LoadedMessageRead: displayReplyAllFormAsync、 displayReplyFormAsync、 getAllInternetHeadersAsync、 getAsFileAsync、 getAttachmentContentAsync、 getInitializationContextAsync、 getSharedPropertiesAsync、 loadCustomPropertiesAsync、 unloadAsync
- Office.Location: getAsync、 setAsync
- Office.Mailbox: addHandlerAsync, displayAppointmentFormAsync, displayMessageFormAsync, displayNewAppointmentFormAsync, displayNewMessageFormAsync, getCallbackTokenAsync, getSelectedItemsAsync, getUserIdentityTokenAsync, loadItemByIdAsync, makeEwsRequestAsync, removeHandlerAsync
- Office.MasterCategories: addAsync、 getAsync、 removeAsync
- Office.MessageCompose: addFileAttachmentAsync, addFileAttachmentFromBase64Async, addHandlerAsync, addItemAttachmentAsync, closeAsync, disableClientSignatureAsync, getAttachmentSAsync, getAttachmentsAsync, getComposeTypeAsync, getConversationIndexAsync, getInitializationContextAsync, getItemClassAsync, getItemClassAsync, getItemIdAsync, getItemIdAsync, getSelectedDataAsync、getSharedPropertiesAsync、isClientSignatureEnabledAsync、loadCustomPropertiesAsync、removeAttachmentAsync、removeHandlerAsync、saveAsync、sendAsync、setSelectedDataAsync
- Office.MessageRead: addHandlerAsync、 displayReplyAllFormAsync、 displayReplyFormAsync、 getAllInternetHeadersAsync、 getAsFileAsync、 getAttachmentContentAsync、 getInitializationContextAsync、 getSharedPropertiesAsync、 loadCustomPropertiesAsync、 removeHandlerAsync
- Office.NotificationMessages: addAsync、 getAllAsync、 removeAsync、 replaceAsync
- Office.Organizer: getAsync
- Office.Recipients: addAsync、 getAsync、 setAsync
- Office.Recurrence: getAsync、 setAsync
- Office.ReplyFormData: コールバック
- Office.RoamingSettings: saveAsync
- Office.Sensitivity: getAsync、 setAsync
- Office.SensitivityLabel: getAsync、 setAsync
- Office.SensitivityLabelsCatalog: getAsync, getIsEnabledAsync
- Office.SessionData: clearAsync、 getAllAsync、 getAsync、 removeAsync、 setAsync
- Office.Settings: addHandlerAsync、 refreshAsync、 removeHandlerAsync、 saveAsync
- Office.Subject: getAsync、 setAsync
- Office.TableBinding: addColumnsAsync、 addRowsAsync、 clearFormatsAsync、 deleteAllDataValuesAsync、 getFormatsAsync、 setFormatsAsync、 setTableOptionsAsync
- Office.Time: getAsync、 setAsync
- Office.UI: addHandlerAsync, displayDialogAsync
例
// The following is an example applicable to content and task pane add-ins.
// The example shows a call to the getSelectedDataAsync method of the Document object.
Office.context.document.getSelectedDataAsync(
Office.CoercionType.Text,
{
valueFormat: Office.ValueFormat.Unformatted,
filterType: Office.FilterType.All
},
(result) => {
if (result.status === Office.AsyncResultStatus.Succeeded) {
const dataValue = result.value; // Get selected data.
console.log('Selected data is ' + dataValue);
} else {
const err = result.error;
console.log(err.name + ": " + err.message);
}
}
);
// The anonymous function passed as the callback argument ((result) => {...}) has a single
// parameter named result that provides access to an AsyncResult object when the function executes.
// When the call to the getSelectedDataAsync method completes, the callback function executes,
// and the following line of code accesses the value property of the AsyncResult object to
// return the data selected in the document:
// const dataValue = result.value;
// Note that other lines of code in the function use the result parameter of the callback function
// to access the status and error properties of the AsyncResult object.
プロパティ
| async |
呼び出されたメソッドの省略可能な |
| diagnostics | エラーが発生した場合に追加情報を提供する可能性があるオブジェクトを取得します。 |
| error | エラーが発生した場合にエラーの説明を提供する Office.Error オブジェクトを取得します。 |
| status | 非同期操作の Office.AsyncResultStatus を取得します。 |
| value | この非同期操作のペイロードまたはコンテンツを取得します (ある場合)。 |
プロパティの詳細
asyncContext
呼び出されたメソッドの省略可能な asyncContext パラメーターに渡されたユーザー定義項目を、渡されたのと同じ状態で取得します。 これにより、呼び出されたメソッドの省略可能な asyncContext パラメーターに渡されるユーザー定義項目 (任意の JavaScript 型 (String、Number、Boolean、Object、Array、Null、Undefined) が返されます。 asyncContext パラメーターに値を渡していない場合は、 Undefined が戻されます。
asyncContext: any;
プロパティ値
any
例
function getDataWithContext() {
const format = "Your data: ";
Office.context.document.getSelectedDataAsync(
Office.CoercionType.Text,
{ asyncContext: format },
showDataWithContext);
}
function showDataWithContext(asyncResult) {
write(asyncResult.asyncContext + asyncResult.value);
}
// Function that writes to a div with id='message' on the page.
function write(message) {
document.getElementById('message').innerText += message;
}
diagnostics
エラーが発生した場合に追加情報を提供する可能性があるオブジェクトを取得します。
diagnostics: any;
プロパティ値
any
注釈
このプロパティは、これらのサポートされている API で次のエラーが発生した場合に追加情報を返します。
サポートされている API
Office.context.mailbox.item.getCallbackTokenAsync
, Office.context.mailbox.item.getUserIdentityTokenAsync
サポートされているエラー
AsyncResult.error.name | AsyncResult.error.message | 返診断オブジェクトの説明 |
|---|---|---|
| HTTPRequestFailure | 要求が失敗しました。 HTTP エラーコードの diagnostics オブジェクトを参照してください。 | JSON オブジェクトの HTTP エラー コード (例: {"HTTPCode":"401"})。 |
| InternalServerError | Exchange サーバーがエラーを返しました。 詳細については、diagnostics オブジェクトを参照してください。 | JSON オブジェクト内の Exchange サーバーからのエラー メッセージ (例: {"ErrorText": "The mailbox database is temporarily unavailable"})。 |
error
エラーが発生した場合にエラーの説明を提供する Office.Error オブジェクトを取得します。
error: Office.Error;
プロパティ値
例
function getData() {
Office.context.document.getSelectedDataAsync(Office.CoercionType.Table, function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
write(asyncResult.error.message);
}
else {
write(asyncResult.value);
}
});
}
// Function that writes to a div with id='message' on the page.
function write(message) {
document.getElementById('message').innerText += message;
}
status
非同期操作の Office.AsyncResultStatus を取得します。
status: AsyncResultStatus;
プロパティ値
例
function getData() {
Office.context.document.getSelectedDataAsync(Office.CoercionType.Table, function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
write(asyncResult.error.message);
}
else {
write(asyncResult.value);
}
});
}
// Function that writes to a div with id='message' on the page.
function write(message) {
document.getElementById('message').innerText += message;
}
value
この非同期操作のペイロードまたはコンテンツを取得します (ある場合)。
value: T;
プロパティ値
T
注釈
引数として渡された関数の AsyncResult オブジェクトには、Document オブジェクトの getSelectedDataAsync メソッドや setSelectedDataAsync メソッドなど、"Async" メソッドのコールバック パラメーターにアクセスします。
注: 特定の "Async" メソッドに対して value プロパティが返す内容は、そのメソッドの目的とコンテキストによって異なります。 To determine what is returned by the value property for an "Async" method, refer to the "Callback value" section of the method's topic.
例
function getData() {
Office.context.document.getSelectedDataAsync(Office.CoercionType.Table, function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
write(asyncResult.error.message);
}
else {
write(asyncResult.value);
}
});
}
// Function that writes to a div with id='message' on the page.
function write(message) {
document.getElementById('message').innerText += message;
}