Skip to content

Commit 5736240

Browse files
[Outlook] (attachments) Update snippet for getAttachmentContentAsync method
[Outlook] (attachments) Update snippet for getAttachmentContentAsync method
1 parent 5706df4 commit 5736240

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

samples/outlook/40-attachments/get-attachment-content.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ script:
99
document.getElementById("attachment-content-compose").addEventListener("click", getAttachmentContentCompose);
1010
document.getElementById("attachment-content-read").addEventListener("click", getAttachmentContentRead);
1111
12-
const item = Office.context.mailbox.item;
13-
1412
function getAttachmentContentCompose() {
15-
// Gets the attachments of the current message or appointment in compose mode.
16-
const options = { asyncContext: { currentItem: item } };
17-
// The getAttachmentsAsync call can only be used in compose mode.
18-
item.getAttachmentsAsync(options, callback);
19-
20-
function callback(result) {
13+
// Gets the attachments of the current message or appointment in compose mode. The getAttachmentsAsync call can only be used in compose mode.
14+
Office.context.mailbox.item.getAttachmentsAsync((result) => {
2115
if (result.status === Office.AsyncResultStatus.Failed) {
2216
console.log(result.error.message);
2317
return;
@@ -30,14 +24,14 @@ script:
3024
3125
for (let i = 0; i < result.value.length; i++) {
3226
// Log the attachment type and its contents to the console.
33-
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
27+
Office.context.mailbox.item.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
3428
}
35-
}
29+
});
3630
}
3731
3832
function getAttachmentContentRead() {
39-
// Gets the attachments of the current message or appointment in read mode.
40-
// The item.attachments call can only be used in read mode.
33+
// Gets the attachments of the current message or appointment in read mode. The item.attachments call can only be used in read mode.
34+
const item = Office.context.mailbox.item;
4135
const attachments = item.attachments;
4236
if (attachments.length <= 0) {
4337
console.log("Mail item has no attachments.");

snippet-extractor-output/snippets.yaml

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8757,16 +8757,9 @@
87578757

87588758

87598759
// Gets the attachments of the current message or appointment in compose
8760-
mode.
8760+
mode. The getAttachmentsAsync call can only be used in compose mode.
87618761

8762-
const options = { asyncContext: { currentItem: item } };
8763-
8764-
// The getAttachmentsAsync call can only be used in compose mode.
8765-
8766-
item.getAttachmentsAsync(options, callback);
8767-
8768-
8769-
function callback(result) {
8762+
Office.context.mailbox.item.getAttachmentsAsync((result) => {
87708763
if (result.status === Office.AsyncResultStatus.Failed) {
87718764
console.log(result.error.message);
87728765
return;
@@ -8779,9 +8772,9 @@
87798772

87808773
for (let i = 0; i < result.value.length; i++) {
87818774
// Log the attachment type and its contents to the console.
8782-
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
8775+
Office.context.mailbox.item.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
87838776
}
8784-
}
8777+
});
87858778
'Office.AppointmentCompose#getAttachmentsAsync:member(1)':
87868779
- >-
87878780
// Link to full sample:
@@ -9812,8 +9805,9 @@
98129805

98139806

98149807
// Gets the attachments of the current message or appointment in read mode.
9808+
The item.attachments call can only be used in read mode.
98159809

9816-
// The item.attachments call can only be used in read mode.
9810+
const item = Office.context.mailbox.item;
98179811

98189812
const attachments = item.attachments;
98199813

@@ -12515,16 +12509,9 @@
1251512509

1251612510

1251712511
// Gets the attachments of the current message or appointment in compose
12518-
mode.
12512+
mode. The getAttachmentsAsync call can only be used in compose mode.
1251912513

12520-
const options = { asyncContext: { currentItem: item } };
12521-
12522-
// The getAttachmentsAsync call can only be used in compose mode.
12523-
12524-
item.getAttachmentsAsync(options, callback);
12525-
12526-
12527-
function callback(result) {
12514+
Office.context.mailbox.item.getAttachmentsAsync((result) => {
1252812515
if (result.status === Office.AsyncResultStatus.Failed) {
1252912516
console.log(result.error.message);
1253012517
return;
@@ -12537,9 +12524,9 @@
1253712524

1253812525
for (let i = 0; i < result.value.length; i++) {
1253912526
// Log the attachment type and its contents to the console.
12540-
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
12527+
Office.context.mailbox.item.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
1254112528
}
12542-
}
12529+
});
1254312530
'Office.MessageCompose#getAttachmentsAsync:member(1)':
1254412531
- >-
1254512532
// Link to full sample:
@@ -13506,8 +13493,9 @@
1350613493

1350713494

1350813495
// Gets the attachments of the current message or appointment in read mode.
13496+
The item.attachments call can only be used in read mode.
1350913497

13510-
// The item.attachments call can only be used in read mode.
13498+
const item = Office.context.mailbox.item;
1351113499

1351213500
const attachments = item.attachments;
1351313501

0 commit comments

Comments
 (0)