1 out of 1 rated this helpful - Rate this topic

AsyncResult object (JavaScript API for Office v1.1)

JavaScript API for Office v1.1

An object which encapsulates the result of an asynchronous request, including status and error information if the request failed.

Last modified: February 25, 2014

AsyncResult
Properties

Name

Description

asyncContext

Gets the user-defined item passed to the optional asyncContext parameter of the invoked method in the same state as it was passed in.

error

Gets an Error object that provides a description of the error, if any error occurred.

status

Gets the status of the asynchronous operation.

value

Gets the payload or content of this asynchronous operation, if any.

When the function you pass to the callback parameter of an "Async" method executes, it receives an AsyncResult object that you can access from the callback function's only parameter.

The following is an example applicable to content and task pane apps. The example shows a call to the getSelectedDataAsync method of the Document object.

Office.context.document.getSelectedDataAsync("text", {valueFormat:"unformatted", filterType:"all"}, 
   function (result) {
      if (result.status === "success")      
         var dataValue = result.value; // Get selected data.
         write('Selected data is ' + dataValue);
      else {            
         var err = result.error; 
         write(err.name + ": " + err.message);
      }
   });
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

The anonymous function passed as the callback argument (function (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:

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

The AsyncResult object is available from the function passed as the argument to the callback parameter of the following methods:

Parent Object

Method

Document(Excel, PowerPoint, Project, and Word only)

getSelectedDataAsync

setSelectedDataAsync

Bindings (Excel and Word only)

addFromPromptAsync

addFromSelectionAsync

getAllAsync

getByIdAsync

releaseByIdAsync

Binding (Excel and Word only)

getDataAsync

setDataAsync

removeHandlerAsync

TableBinding (Excel and Word only)

addRowsAsync

deleteAllDataValuesAsync

Settings (Excel, PowerPoint, and Word only)

refreshAsync

saveAsync

CustomXmlNode (Word only)

getNodesAsync

getNodeValueAsync

getXmlAsync

setNodeValueAsync

setXmlAsync

CustomXmlPart (Word only)

deleteAsync

getNodesAsync

getXmlAsync

CustomXmlParts (Word only)

addAsync

getByIdAsync

getByNamespaceAsync

CustomXmlPrefixMappings (Word only)

addNamespaceAsync

getNamespaceAsync

getPrefixAsync

Mailbox (Outlook only)

getUserIdentityTokenAsync

makeEwsRequestAsync

CustomProperties (Outlook only)

saveAsync

Item (Outlook only)

loadCustomPropertiesAsync

RoamingSettings (Outlook only)

saveAsync

App types

Content app, Mail app, Task pane app

Supported clients

Access app for SharePoint, Excel 2013, Excel 2013 SP1, Excel Online, Word 2013, Word 2013 SP1, Outlook 2013, Outlook 2013 SP1, Outlook Web App, OWA for Devices, PowerPoint 2013, PowerPoint 2013 SP1, Project Professional 2013, and Project 2013 SP1

Library

Office.js

Namespace

Office

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.