0

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?

Gertsen
  • 1,078
  • 20
  • 36
  • Sounds like you need to post this as an issue to the [OfficeJS repo](https://github.com/OfficeDev/office-js/issues) at github. – Eugene Astafiev Sep 15 '22 at 15:20
  • Hello, can you please confirm that you are calling Office.actions.associate in your add-in? We have this documented online: https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/autolaunch#implement-event-handling – Outlook Add-ins Team - MSFT Sep 15 '22 at 22:21
  • @OutlookAdd-insTeam-MSFT I can confirm that I'm calling that (which is why it works in the browser version of Outlook). I will update the question to reflect this. – Gertsen Sep 16 '22 at 06:29
  • 1
    Hi @Gertsen - The fact that this issue does not repro when the add-in is marked for debugging suggests that your 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. Can you please confirm? – Outlook Add-ins Team - MSFT Sep 26 '22 at 17:41
  • I hope that is correct, since that means there is a solution to the problem. Not sure how to evaluate if the script is beyond ECMAScript 2016 or not though. – Gertsen Sep 27 '22 at 09:51
  • @OutlookAdd-insTeam-MSFT - Update: I have found a few usages of ECMAScript 2017, 2018 and 2019 in our code. I hope to have a new version ready for testing within a few weeks. I will report back after the tests. – Gertsen Sep 27 '22 at 12:00
  • @OutlookAdd-insTeam-MSFT I can confirm that after rewriting our JavaScript code, the events now fire as expected. Could you submit an answer for me to accept? – Gertsen Oct 05 '22 at 06:12
  • 1
    I'm glad that the issue was resolved! Answer submitted. – Outlook Add-ins Team - MSFT Oct 06 '22 at 17:50

1 Answers1

1

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.