We need to act on the OnNewMessageCompose
and OnMessageRecipientsChanged
events, and have registered them in the app manifest as shown below.
This works in the browser version of Outlook: outlook.office.com
But it doesn't work in the Windows client. (Outlook 365, currently testing with version 2209 build 16.0.15629.20068 32-bit)
This has worked for us earlier, but recently it stopped working in the update channel: Current Channel (Preview)
Switching to the non-preview update channel temporarily solved this, but now it is not working in either channel.
JavaScript event handlers (simplified a bit for this example):
function EventOnCompose(event) {
HandleComposeEvent(event, false)
.then((result) => console.log(result))
.catch((err) => {
console.error(err);
})
.finally(() => {
console.info("Event completed");
event.completed();
});
}
function EventOnRecipientsChanged(event) {
HandleRecipientsChangedEvent(event, false)
.then((result) => console.log(result))
.catch((err) => {
console.error(err);
})
.finally(() => {
console.info("Event completed");
event.completed();
});
}
At the very bottom of addinfunction.js, I have the following code to ensure the actions are associated with these events.
Office.actions.associate("EventOnCompose", EventOnCompose);
Office.actions.associate("EventOnRecipientsChanged", EventOnRecipientsChanged);
Another symptom we're experiencing, when running the app in the Windows Client, with Debugging enabled, it does trigger the events (and stops as soon as debugging is disabled again). When the debugger is disabled, it shows the following message in the top of the compose window:
We're sorry, we couldn't access <app-name>. Make sure you have a network connection. If the problem continues, please try again later. Dismiss
The application manifest looks like: (trimmed down to mainly show the LaunchEvents-related elements.)
<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" xsi:type="MailApp">
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
<Hosts>
<Host xsi:type="MailHost">
<Runtimes>
<Runtime resid="functionFile">
<Override type="javascript" resid="functionFileJs"/>
</Runtime>
</Runtimes>
<DesktopFormFactor>
<ExtensionPoint xsi:type="LaunchEvent">
<LaunchEvents>
<LaunchEvent Type="OnNewMessageCompose" FunctionName="EventOnCompose"/>
<LaunchEvent Type="OnMessageRecipientsChanged" FunctionName="EventOnRecipientsChanged"/>
</LaunchEvents>
<SourceLocation resid="functionFile"/>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Urls>
<bt:Url id="functionFileJs" DefaultValue="https://---host---/js/addinfunction.js"/>
<bt:Url id="functionFile" DefaultValue="https://---host---/function.html"/>
</bt:Urls>
</Resources>
<WebApplicationInfo>
<Id>--- guid ---</Id>
<Resource>api://---host---/---guid---</Resource>
<Scopes>
<Scope>profile</Scope>
</Scopes>
</WebApplicationInfo>
</VersionOverrides>
</VersionOverrides>
</OfficeApp>
Important note: We tried debugging, but since the events aren't triggering, that doesn't help.
Does anyone have a fix for this, or ideas on what to look into as a possible cause of this problematic behavior?
The fact that this issue does not repro when the add-in is marked for debugging suggests that the code might be using syntax that is beyond ECMAScript 2016. The solution here is to use syntax that is only supported up to ECMAScript 2016.