Office.AsyncResult interface

要求が失敗した場合の状態やエラー情報など、非同期要求の結果をカプセル化するオブジェクト。

"Async" メソッドのパラメーターに callback 渡す関数が実行されると、関数の唯一のパラメーターからアクセスできる AsyncResult オブジェクトを callback 受け取ります。

注釈

// 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.

プロパティ

asyncContext

呼び出されたメソッドの省略可能な asyncContext パラメーターに渡されたユーザー定義項目を、渡されたのと同じ状態で取得します。 これにより、呼び出されたメソッドの省略可能 asyncContext なパラメーターに渡されるユーザー定義項目 (任意の JavaScript 型 (String、Number、Boolean、Object、Array、Null、Undefined) が返されます。 asyncContext パラメーターに値を渡していない場合は、 Undefined が戻されます。

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"}
InternalServerErrorExchange サーバーがエラーを返しました。 詳細については、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 オブジェクトの メソッドや setSelectedDataAsync メソッドなどgetSelectedDataAsync、"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; 
}