Skip to content

Commit 9c8796f

Browse files
committed
Add Outlook add-in command that invokes a function
1 parent b27853d commit 9c8796f

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

manifest.outlook.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@
6666
<SourceLocation resid="Taskpane.Url" />
6767
</Action>
6868
</Control>
69+
<Control xsi:type="Button" id="ActionButton">
70+
<Label resid="ActionButton.Label"/>
71+
<Supertip>
72+
<Title resid="ActionButton.Label"/>
73+
<Description resid="ActionButton.Tooltip"/>
74+
</Supertip>
75+
<Icon>
76+
<bt:Image size="16" resid="Icon.16x16"/>
77+
<bt:Image size="32" resid="Icon.32x32"/>
78+
<bt:Image size="80" resid="Icon.80x80"/>
79+
</Icon>
80+
<Action xsi:type="ExecuteFunction">
81+
<FunctionName>action</FunctionName>
82+
</Action>
83+
</Control>
6984
</Group>
7085
</OfficeTab>
7186
</ExtensionPoint>
@@ -85,9 +100,11 @@
85100
<bt:ShortStrings>
86101
<bt:String id="GroupLabel" DefaultValue="Contoso Add-in"/>
87102
<bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
103+
<bt:String id="ActionButton.Label" DefaultValue="Perform an action"/>
88104
</bt:ShortStrings>
89105
<bt:LongStrings>
90106
<bt:String id="TaskpaneButton.Tooltip" DefaultValue="Opens a pane displaying all available properties."/>
107+
<bt:String id="ActionButton.Tooltip" DefaultValue="Perform an action when clicked."/>
91108
</bt:LongStrings>
92109
</Resources>
93110
</VersionOverrides>

src/commands/commands.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,37 @@
33
* See LICENSE in the project root for license information.
44
*/
55

6-
(() => {
7-
// The initialize function must be run each time a new page is loaded
8-
Office.initialize = () => {
6+
Office.onReady(info => {
7+
// If needed, Office.js is ready to be called
8+
});
99

10-
};
10+
/**
11+
* Shows a notification when the add-in command is executed.
12+
* @param event
13+
*/
14+
function action(event: Office.AddinCommands.Event) {
15+
const message: Office.NotificationMessageDetails = {
16+
type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
17+
message: "Performed action.",
18+
icon: "Icon.80x80",
19+
persistent: true
20+
}
21+
22+
// Show a notification message
23+
Office.context.mailbox.item.notificationMessages.replaceAsync("action", message);
24+
25+
// Be sure to indicate when the add-in command function is complete
26+
event.completed();
27+
}
28+
29+
function getGlobal() {
30+
return (typeof self !== "undefined") ? self :
31+
(typeof window !== "undefined") ? window :
32+
(typeof global !== "undefined") ? global :
33+
undefined;
34+
}
35+
36+
const g = getGlobal() as any;
1137

12-
// Add any ui-less function here
13-
})();
38+
// the add-in command functions need to be available in global scope
39+
g.action = action;

0 commit comments

Comments
 (0)