OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
669 stars 95 forks source link

New Outlook: EventType.SelectedItemsChanged does not trigger reliably #4637

Open senden9 opened 2 months ago

senden9 commented 2 months ago

Multi Item selection does not trigger reliably in new Outlook Desktop and Outlook Web. In the old outlook Desktop it works fine.

Your Environment

Expected behavior

Office.context.mailbox.addHandlerAsync(Office.EventType.SelectedItemsChanged, …) triggers on every change of selection. Like documented at https://learn.microsoft.com/en-us/javascript/api/requirement-sets/outlook/requirement-set-1.14/office?view=common-js-preview#eventtype-string:

Name Type Description
SelectedItemsChanged String One or more messages are selected or deselected.

Current behavior

Office.context.mailbox.addHandlerAsync(Office.EventType.SelectedItemsChanged, …) triggers only on some changes. See video below.

Steps to reproduce

  1. Load provided Plugin in Outlook Web or the new Outlook Desktop. The provided plugin contains the code from https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/item-multi-select
  2. Select one Mail
  3. Open Add-In Task Plane
  4. Hold Shift and select a second mail.
  5. Observe how the text in the task plane do not changes. It should change
  6. Select a additional mail. You have three mails selected in total.
  7. Observe how the task plane show three mails selected like it should.
  8. Deselect one mail. You have two mails in total selected now.
  9. Observe how the task plane show two mails selected like it should.

Link to live example(s)

The Repository https://github.com/senden9/OfficeJS-Issue-Example/ contains the Add-In for this example. The Javascript code can be found at https://github.com/senden9/OfficeJS-Issue-Example/blob/88711d940dfaff927d44c61e2b7e7ab618b3f121/src/taskpane/taskpane.js#L8-L46

Provide additional details

In the old Outlook desktop the example works perfectly fine.

Workaround

Workaround: Either use a timer to check with Office.context.mailbox.getSelectedItemsAsync for selected mails or check also for multible mails when Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, … triggers.

Useful logs

Screencast:

https://github.com/OfficeDev/office-js/assets/905857/c5451507-752f-4bf7-9381-d5290fd55ed2

ottD commented 1 month ago

We are facing the same issue. The Office.EventType.SelectedItemsChanged event consistently fails to fire on OWA and new Outlook when changing the email selection from one to two selected emails just as @senden9 has outlined. This bug significantly impacts add-ins supporting item multi-select as the selected emails shown in the add-in task pane do not reflect the actual email selection in the user's mailbox which is confusing to users. The suggested work arounds using a timer or subscribing to the Office.EventType.ItemChanged event are insufficient as they defeat the purpose of the Office.EventType.SelectedItemsChanged event which is specifically designed to deal with item selection changes in item multi-select add ins as documented here