Office.AsyncResult interface

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

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

注釈

使用元

// 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 パラメーターに渡されたユーザー定義項目 (String、Number、Boolean、Object、Array、Null、Undefined の任意の JavaScript 型にすることができます) が返されます。 asyncContext パラメーターに値を渡していない場合は、 Undefined が戻されます。

diagnostics

エラーが発生した場合に追加情報を提供する可能性のあるオブジェクトを取得します。

error

エラーが発生した場合に、エラーの説明を提供する Office.Error オブジェクトを取得します。

status

非同期操作の Office.AsyncResultStatus を取得します。

value

この非同期操作のペイロードまたはコンテンツを取得します (ある場合)。

プロパティの詳細

asyncContext

呼び出されたメソッドの省略可能な asyncContext パラメーターに渡されたユーザー定義項目を、渡されたときと同じ状態で取得します。 これにより、呼び出されたメソッドのオプションの asyncContext パラメーターに渡されたユーザー定義項目 (String、Number、Boolean、Object、Array、Null、Undefined の任意の JavaScript 型にすることができます) が返されます。 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 オブジェクト (例: {"HTTPCode":"401"}) の HTTP エラー コード。
InternalServerError Exchange サーバーがエラーを返しました。 詳細については、diagnostics オブジェクトを参照してください。 JSON オブジェクト ( {"ErrorText": "The mailbox database is temporarily unavailable"} など) の Exchange サーバーからのエラー メッセージ。

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;
}