I am trying to test a simple console.log print test when I move from one email to another in outlook. I am following the instructions from Microsoft here: https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/pinnable-taskpane#handling-ui-updates-based-on-currently-selected-message
My manifest file already supports pinning and I use pinning in all my outlook addin projects.
I followed this code from microsoft yet it doesn't seem to do anything in the developer console:
function itemChanged(eventArgs) {
// Update UI based on the new current item
UpdateTaskPaneUI(Office.context.mailbox.item);
}
// Example implementation
function UpdateTaskPaneUI(item)
{
// Assuming that item is always a read item (instead of a compose item).
if (item != null) console.log(item.subject);
}
Office.initialize = function (reason) {
$(document).ready(function () {
// Set up ItemChanged event
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, itemChanged);
UpdateTaskPaneUI(Office.context.mailbox.item);
});
};
I was assuming that I was going to receive the subject of which ever email I was highlighted on in outlook but nothing happened. I also double clicked on an email to see if the event was fired only by the email being in its own window and nothing happened still.
I am running Microsoft® Outlook® for Microsoft 365 MSO (Version 2111 Build 16.0.14701.20254) 64-bit
I was able to get it to work. I was first testing in the dev tool's console so I assumed that would have worked but it was casuing me errors. The moment I tested the code in the javascript for the outlook addin itself it started to work:
Office.onReady((info) => {
$(document).ready(function () {
function itemChanged(eventArgs) {
// Update UI based on the new current item
UpdateTaskPaneUI(Office.context.mailbox.item);
}
// Example implementation
function UpdateTaskPaneUI(item)
{
// Assuming that item is always a read item (instead of a compose item).
if (item != null) console.log(item.subject);
}
// Set up ItemChanged event
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, itemChanged);
UpdateTaskPaneUI(Office.context.mailbox.item);
})