Ewa.AsyncResult.getCode()

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example

Gets the return code of the specified asynchronous method call.

var value = Ewa.AsyncResult.getCode();

Return Value

AsyncErrorCode Enumeration

Remarks

The [AsyncResult] object is passed as an argument to the callback specified in the asynchronous method call. The [AsyncResult] object contains the return code that results from the asynchronous operation. The [AsyncResult.getCode] method returns the return code as an [AsyncErrorCode] enumeration that specifies the success or failure of the operation. If the asynchronous operation is successful, [AsyncResult.getCode] returns [AsyncErrorCode.Success].

If an error occurs during an asynchronous operation, [AsyncResult.getCode] returns an [AsyncErrorCode] enumeration constant that describes the error.

Example

The following code example shows how to get a range asynchronously and then uses the AsyncResult.getCode method to get the error code from an [AsyncResult] object.

<script type="text/javascript">
     
var ewa = null;
    
// Add event handler for onload event.
if (window.attachEvent) 
{ 
    window.attachEvent("onload", ewaOmPageLoad);    
} 
else 
{ 
    window.addEventListener("DOMContentLoaded", ewaOmPageLoad, false); 
}

// Add event handler for applicationReady event.
function ewaOmPageLoad() 
{         
    Ewa.EwaControl.add_applicationReady(getEwa); 
} 

function getEwa()
{
    // Get a reference to the Ewa object.
    ewa = Ewa.EwaControl.getInstances().getItem(0);
    getRangeAsync();
}

function getRangeAsync()
{
    // Get a range asynchronously using A1 notation.
    ewa.getActiveWorkbook().getRangeA1Async("Sheet3!B2", getRangeComplete, null);
}

function getRangeComplete(asyncResult)
{    
    // If getRangeA1Async failed, get error code.
    if (!asyncResult.getSucceeded())
    {
       // Get the error code.
        var errorCode = asyncResult.getCode();
        switch (errorCode)
        {
            case Ewa.AsyncErrorCode.InternalError:
                alert("An internal error occurred.");
                break;
            case Ewa.AsyncErrorCode.TimedOut:
                alert("The operation timed out.");
                break;            
            case Ewa.AsyncErrorCode.InvalidNamedItem:
                alert("The named item is undefined or unpublished.");
                break;
            case Ewa.AsyncErrorCode.SettingValuesError:
                alert("Excel Calculation Services is unable to set the values.");
                break;
            case Ewa.AsyncErrorCode.RangeSizeError:
                alert("The array indices exceed the range columns and/or rows. Or the range columns and/or rows exceed the array indices.");
                break;            
        } // End switch.
    } // End if.
    
    // Get the range object from the getRangeA1Async call
    var range = asyncResult.getReturnValue();
       
    // Display the range address in A1 format
    window.status = range.getAddressA1();
}
</script>

See Also

Reference

Ewa.AsyncResult Methods

Concepts

Ewa Namespace