/
office.asyncresult.yml
230 lines (199 loc) · 8.46 KB
/
office.asyncresult.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
### YamlMime:TSType
name: Office.AsyncResult
uid: 'office!Office.AsyncResult:interface'
package: office!
fullName: Office.AsyncResult
summary: >-
An object which encapsulates the result of an asynchronous request, including status and error information if the
request failed.
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.
remarks: |-
#### Examples
```TypeScript
// 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.
```
isPreview: false
isDeprecated: false
type: interface
properties:
- name: asyncContext
uid: 'office!Office.AsyncResult#asyncContext:member'
package: office!
fullName: asyncContext
summary: >-
Gets the user-defined item passed to the optional `asyncContext` parameter of the invoked method in the same state
as it was passed in. This returns the user-defined item (which can be of any JavaScript type: String, Number,
Boolean, Object, Array, Null, or Undefined) passed to the optional `asyncContext` parameter of the invoked method.
Returns Undefined, if you didn't pass anything to the asyncContext parameter.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'asyncContext: any;'
return:
type: any
description: |-
#### Examples
```TypeScript
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;
}
```
- name: diagnostics
uid: 'office!Office.AsyncResult#diagnostics:member'
package: office!
fullName: diagnostics
summary: 'Gets an object that may provide additional information if an [error](xref:office!Office.Error:interface) occurred.'
remarks: >-
This property returns additional information if the following errors occur with these supported APIs.
*Supported APIs*
`Office.context.mailbox.item.getCallbackTokenAsync`<!-- -->,
`Office.context.mailbox.item.getUserIdentityTokenAsync`
*Supported errors* <table> <tr> <th><code>AsyncResult.error.name</code>
</th><th><code>AsyncResult.error.message</code></th> <th>Description of diagnostics object returned</th> </tr>
<tr> <td><strong>HTTPRequestFailure</strong></td> <td>The request has failed. Please look at the diagnostics
object for the HTTP error code.</td> <td>The HTTP error code in a JSON object e.g., <code>{<!--
-->"HTTPCode":"401"<!-- -->}</code>.</td> </tr> <tr> <td><strong>InternalServerError</strong></td> <td>The
Exchange server returned an error. Please look at the diagnostics object for more information.</td> <td>The error
message from the Exchange server in a JSON object e.g., <code>{<!-- -->"ErrorText": "The mailbox database is
temporarily unavailable"<!-- -->}</code>.</td> </tr> </table>
isPreview: false
isDeprecated: false
syntax:
content: 'diagnostics: any;'
return:
type: any
- name: error
uid: 'office!Office.AsyncResult#error:member'
package: office!
fullName: error
summary: >-
Gets an [Office.Error](xref:office!Office.Error:interface) object that provides a description of the error, if any
error occurred.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'error: Office.Error;'
return:
type: '<xref uid="office!Office.Error:interface" />'
description: |-
#### Examples
```TypeScript
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;
}
```
- name: status
uid: 'office!Office.AsyncResult#status:member'
package: office!
fullName: status
summary: 'Gets the [Office.AsyncResultStatus](xref:office!Office.AsyncResultStatus:enum) of the asynchronous operation.'
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'status: AsyncResultStatus;'
return:
type: '<xref uid="office!Office.AsyncResultStatus:enum" />'
description: |-
#### Examples
```TypeScript
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;
}
```
- name: value
uid: 'office!Office.AsyncResult#value:member'
package: office!
fullName: value
summary: 'Gets the payload or content of this asynchronous operation, if any.'
remarks: >-
You access the AsyncResult object in the function passed as the argument to the callback parameter of an "Async"
method, such as the `getSelectedDataAsync` and `setSelectedDataAsync` methods of the
[Document](xref:office!Office.Document:interface) object.
**Note**: What the value property returns for a particular "Async" method varies depending on the purpose and
context of that method. To determine what is returned by the value property for an "Async" method, refer to the
"Callback value" section of the method's topic.
#### Examples
```TypeScript
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;
}
```
isPreview: false
isDeprecated: false
syntax:
content: 'value: T;'
return:
type: T