Office.AsyncResult interface
Um objeto que encapsula o resultado de uma solicitação assíncrona, incluindo informações de status e de erro caso a solicitação tenha falhado.
Quando a função que transmite ao callback parâmetro de um método "Assíncrono" é executada, recebe um objeto AsyncResult ao qual pode aceder a callback partir do único parâmetro da função.
Comentários
Usada por
- Office: selecione
- Office.AppointmentCompose: addFileAttachmentAsync, addFileAttachmentFromBase64Async, addHandlerAsync, addItemAttachmentAsync, disableClientSignatureAsync, getAttachmentContentAsync, getAttachmentsAsync, getInitializationContextAsync, getItemIdAsync, getSelectedDataAsync, getSharedPropertiesAsync, isClientSignatureEnabledAsync, 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, 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, downloadAsync
- 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, getAttachmentContentAsync, getAttachmentsAsync, getComposeTypeAsync, getConversationIndexAsync, getInitializationContextAsync, getItemClassAsync, 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: chamada de retorno
- 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
Exemplos
// 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.
Propriedades
| async |
Obtém o item definido pelo utilizador transmitido para o parâmetro opcional |
| diagnostics | Obtém um objeto que pode fornecer informações adicionais se ocorrer um erro . |
| error | Obtém um objeto Office.Error que fornece uma descrição do erro, caso tenha ocorrido algum erro. |
| status | Obtém o Office.AsyncResultStatus da operação assíncrona. |
| value | Obtém a carga ou o conteúdo desta operação assíncrona, caso haja algum. |
Detalhes da propriedade
asyncContext
Obtém o item definido pelo utilizador transmitido para o parâmetro opcional asyncContext do método invocado no mesmo estado em que foi transmitido. Isto devolve o item definido pelo utilizador (que pode ser de qualquer tipo JavaScript: Cadeia, Número, Booleano, Objeto, Matriz, Nulo ou Indefinido) transmitido para o parâmetro opcional asyncContext do método invocado. Retorna Undefined, se você não passou nada para o parâmetro asyncContext.
asyncContext: any;
Valor da propriedade
any
Exemplos
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
Obtém um objeto que pode fornecer informações adicionais se ocorrer um erro .
diagnostics: any;
Valor da propriedade
any
Comentários
Esta propriedade devolve informações adicionais se ocorrerem os seguintes erros com estas APIs suportadas.
APIs suportadas
Office.context.mailbox.item.getCallbackTokenAsync
, Office.context.mailbox.item.getUserIdentityTokenAsync
Erros suportados
AsyncResult.error.name | AsyncResult.error.message | Descrição do objeto diagnóstico devolvido |
|---|---|---|
| HTTPRequestFailure | A solicitação falhou. Examine o objeto de diagnóstico para o código de erro HTTP. | O código de erro HTTP num objeto JSON, por exemplo, {"HTTPCode":"401"}. |
| InternalServerError | O servidor do Exchange retornou um erro. Para saber mais, confira o objeto de diagnóstico. | A mensagem de erro do servidor Exchange num objeto JSON, por exemplo, {"ErrorText": "The mailbox database is temporarily unavailable"}. |
error
Obtém um objeto Office.Error que fornece uma descrição do erro, caso tenha ocorrido algum erro.
error: Office.Error;
Valor da propriedade
Exemplos
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
Obtém o Office.AsyncResultStatus da operação assíncrona.
status: AsyncResultStatus;
Valor da propriedade
Exemplos
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
Obtém a carga ou o conteúdo desta operação assíncrona, caso haja algum.
value: T;
Valor da propriedade
T
Comentários
Pode aceder ao objeto AsyncResult na função transmitida como argumento para o parâmetro de chamada de retorno de um método "Assíncrono", como os getSelectedDataAsync métodos e setSelectedDataAsync do objeto Documento .
Nota: o que a propriedade de valor devolve para um determinado método "Assíncrono" varia consoante a finalidade e o contexto desse método. To determine what is returned by the value property for an "Async" method, refer to the "Callback value" section of the method's topic.
Exemplos
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;
}