0

I am trying to update TaskPane HTML elements upon event OnMessageRecipientsChanged gets fired. The event is received successfully however, I am unable to access HTML elements using:

document.getElementById("item-subject").innerHTML = "Testing..."

Also, this element is available in Office.OnReady() and I am able to update it there but I instead want to do this onMessageRecipientsChanged event.

This works:

Office.onReady(function () {
  $(document).ready(function () {
    document.getElementById("item-subject").innerHTML = "Testing...";
  });
});

This doesn't work:

function onMessageRecipientsChangedHandler(event) {
  document.getElementById("item-subject").innerHTML = "Testing...";
}

How can I get this to work?

RAF
  • 11
  • 2
  • I could not reproduce this issue on Windows Desktop Outlook or Outlook Web (don't have a Mac to try Mac Outlook). Which client are you seeing this issue on? I am not seeing any code where you are registering your handler with addHandlerAsync method, is that what you're missing by any chance: Office.context.mailbox.item.addHandlerAsync( Office.EventType.RecipientsChanged, onMessageRecipientsChangedHandler, function (result) { // ... }); – Outlook Add-ins Team - MSFT May 12 '22 at 21:43
  • Thank you @OutlookAdd-insTeam-MSFT! I had hooked up event as below: `Office.actions.associate("onMessageRecipientsChangedHandler", onMessageRecipientsChangedHandler);` I tried your approach too but now I am getting a different error: `Office.initialize = function () { $(document).ready(function () { Office.context.mailbox.addHandlerAsync( Office.EventType.RecipientsChanged, onMessageRecipientsChangedHandler, function (result) {...} ); }); };` **Error:** Uncaught Error Function addHandlerAsync has invalid parameters. – RAF May 16 '22 at 12:27
  • Which client (Outlook on Windows, Mac, Web, ..) and version are you using? Is there any chance for you to share the [minimal] code that demonstrates the issue as a snippet in ScriptLab add-in that you can find in Outlook Add-ins store? – Outlook Add-ins Team - MSFT May 16 '22 at 21:53
  • Please find more details: **Windows 11 Microsoft® Outlook® for Microsoft 365 MSO (Version 2111 Build 16.0.14701.20278) 64-bit** `Office.Ready((info) = function () { $(document).ready(function () { Office.context.mailbox.addHandlerAsync( Office.EventType.RecipientsChanged, onMessageRecipientsChangedHandler, function (result) { Office.context.document.getElementById("item-subject").innerHTML = "Updated..."; } } ); }); });` Above code is part of an plugin named **launchevent.js** registered under **webpack.config.js** – RAF May 19 '22 at 08:41
  • 1
    Just to add to that I don't have access to Script Lab for Outlook due to organizational policies but I'll give it a go on my personal laptop – RAF May 19 '22 at 10:23

0 Answers0