Search code examples
outlookoutlook-addinoffice-addinsadd-inoutlook-web-addins

How to get Attendees details by onAppointmentAttendeesChangedHandler function in outlook add-in


I am new to the outlook add-in. I have configured my outlook add-in as event-based activation as per this link https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/autolaunch?tabs=xmlmanifest

When I'm removing any person from meeting at that time I'm not getting their name in event. I have provided the code.

manifest.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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">
  <Id>37cba818-c575-4ac2-85fe-332d9eae8213</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contaso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Contaso-outlook-addin" />
  <Description DefaultValue="A template to get started." />
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-64.png" />
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-128.png" />
  <SupportUrl DefaultValue="https://www.contoso.com/help" />
  <AppDomains>
   <AppDomain>https://localhost:3000</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Mailbox" />
  </Hosts>
  <Requirements>
    <Sets>
      <Set Name="Mailbox" MinVersion="1.1" />
    </Sets>
  </Requirements>
  <FormSettings>
    <Form xsi:type="ItemRead">
      <DesktopSettings>
        <SourceLocation DefaultValue="https://localhost:3000/taskpane.html" />
        <RequestedHeight>250</RequestedHeight>
      </DesktopSettings>
    </Form>
  </FormSettings>
  <Permissions>ReadWriteItem</Permissions>
  <Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
  </Rule>
  <DisableEntityHighlighting>false</DisableEntityHighlighting>
  <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">
      <Requirements>
        <bt:Sets DefaultMinVersion="1.10">
          <bt:Set Name="Mailbox" />
        </bt:Sets>
      </Requirements>
      <Hosts>
        <Host xsi:type="MailHost">
          <!-- Event-based activation happens in a lightweight runtime.-->
          <Runtimes>
            <!-- HTML file including reference to or inline JavaScript event handlers.
                 This is used by Outlook on the web and Outlook on the new Mac UI. -->
            <Runtime resid="WebViewRuntime.Url">
              <!-- JavaScript file containing event handlers. This is used by Outlook on Windows. -->
              <Override type="javascript" resid="JSRuntime.Url" />
            </Runtime>
          </Runtimes>
          <DesktopFormFactor>
            <FunctionFile resid="Commands.Url" />
            <ExtensionPoint xsi:type="MessageReadCommandSurface">
              <OfficeTab id="TabDefault">
                <Group id="msgReadGroup">
                  <Label resid="GroupLabel" />
                  <Control xsi:type="Button" id="msgReadOpenPaneButton">
                    <Label resid="TaskpaneButton.Label" />
                    <Supertip>
                      <Title resid="TaskpaneButton.Label" />
                      <Description resid="TaskpaneButton.Tooltip" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ShowTaskpane">
                      <SourceLocation resid="Taskpane.Url" />
                    </Action>
                  </Control>
                </Group>
              </OfficeTab>
            </ExtensionPoint>

            <!-- Can configure other command surface extension points for add-in command support. -->

            <!-- Enable launching the add-in on the included events. -->
            <ExtensionPoint xsi:type="LaunchEvent">
              <LaunchEvents>

                <LaunchEvent Type="OnAppointmentSend" FunctionName="onAppointmentSendHandler"
                SendMode="PromptUser"
                />

                <LaunchEvent Type="OnAppointmentAttendeesChanged"
                  FunctionName="onAppointmentAttendeesChangedHandler" />

                <LaunchEvent Type="OnAppointmentTimeChanged"
                  FunctionName="onAppointmentTimeChangedHandler" />

                <!-- Other available events -->
                <!--
                <LaunchEvent Type="OnNewMessageCompose" FunctionName="onNewMessageComposeHandler" />
                <LaunchEvent Type="OnNewAppointmentOrganizer"
                  FunctionName="onNewAppointmentComposeHandler" />
                <LaunchEvent Type="OnMessageAttachmentsChanged" FunctionName="onMessageAttachmentsChangedHandler"
                />
                <LaunchEvent Type="OnAppointmentAttachmentsChanged"
                FunctionName="onAppointmentAttachmentsChangedHandler" />
                <LaunchEvent Type="OnMessageRecipientsChanged" FunctionName="onMessageRecipientsChangedHandler" />
                
               
                <LaunchEvent Type="OnAppointmentRecurrenceChanged"
                FunctionName="onAppointmentRecurrenceChangedHandler" />
                <LaunchEvent Type="OnInfoBarDismissClicked" FunctionName="onInfobarDismissClickedHandler" />
                <LaunchEvent Type="OnMessageSend" FunctionName="onMessageSendHandler" SendMode="PromptUser" />
               
                <LaunchEvent Type="OnMessageCompose" FunctionName="onMessageComposeHandler" />
                <LaunchEvent Type="OnAppointmentOrganizer" FunctionName="onAppointmentOrganizerHandler" />
                -->
              </LaunchEvents>
              <!-- Identifies the runtime to be used (also referenced by the Runtime element). -->
              <SourceLocation resid="WebViewRuntime.Url" />
            </ExtensionPoint>
          </DesktopFormFactor>
        </Host>
      </Hosts>
      <Resources>
        <bt:Images>
          <bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png" />
          <bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png" />
          <bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png" />
        </bt:Images>
        <bt:Urls>
          <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html" />
          <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html" />
          <bt:Url id="WebViewRuntime.Url" DefaultValue="https://localhost:3000/commands.html" />
          <!-- Entry needed for Outlook on Windows. -->
          <bt:Url id="JSRuntime.Url" DefaultValue="https://localhost:3000/launchevent.js" />
        </bt:Urls>
        <bt:ShortStrings>
          <bt:String id="ActionButton.Label" DefaultValue="Perform an action" />
          <bt:String id="GroupLabel" DefaultValue="Contaso" />
          <bt:String id="TaskpaneButton.Label" DefaultValue="Contaso" />
        </bt:ShortStrings>
        <bt:LongStrings>
          <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Open Contaso Taskpane" />
        </bt:LongStrings>
      </Resources>
    </VersionOverrides>
  </VersionOverrides>
</OfficeApp>

launchevent.js

function onAppointmentSendHandler(event) {
  debugger;
  setSubject(event);
}
function onAppointmentAttendeesChangedHandler(event) {
  setSubject(event);
}

function onAppointmentTimeChangedHandler(event) {
  setSubject(event);
}

function setSubject(event) {
  debugger;
  console.log("event", event);

}
if (Office.context.platform === Office.PlatformType.PC || Office.context.platform == null) {
  Office.actions.associate("onAppointmentSendHandler", onAppointmentSendHandler);
  Office.actions.associate("onAppointmentAttendeesChangedHandler", onAppointmentAttendeesChangedHandler);
  Office.actions.associate("onAppointmentTimeChangedHandler", onAppointmentTimeChangedHandler);
}

Now, when I'm removing or adding any receipt from the appointment at that time I'm not getting attendees' details. I attached the image of the function when I debugged it. You can see in the function result I'm not getting anything.

I added the attendees from here(You can see in the image). Adding attendees so, can anyone guide me to where I have done a mistake?

Function Result


Solution

  • You may get the actual values using the Office.context.mailbox.item.requiredAttendees.getAsync method call.

    The Office.RecipientsChangedFields interface which represents RecipientsChangedEventArgs.changedRecipientFields object gives a basic information what field has been changed. In your scenario this is requiredAttendees which is set if required attendees were changed.

    Be aware, you can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team goes through the planning process.