2
votes

We have enabled task pane pinning in our manifest for an Outlook add-in and noticed that the pinning support is now available in the Outlook Office online in addition to the Windows Outlook 2016 client.

However, the ItemChange event does not seem to be triggered consistently when switching mail items (I am unable to discern any rhyme or reason on when it gets fired).

We are listening for this event using the addHandlerAsync method. Is this a bug?

2
ItemChange fires when the item actually changes, but when you simply change the selection.Dmitry Streblechenko
AddHandlerAsync is indeed the correct way to use this. Can you describe what you are doing when you expect the itemchanged event to be fired? Based on the title, this only happens in OWA and not the Desktop Client? Or on both? Note that OWA has conversations in the reading pane and the desktop client does not. (Is it possible that you are only seeing the event when you switch messages in one of the two places?)Outlook Add-ins Team - MSFT
@OutlookAdd-insTeam-MSFT We were attempting to select a new mail item in the mail item list by using a mouse click (changing the currently selected mail). The behaviour is only observed in OWA (Firefox/Chrome). I am sorry I did not get the last question in your comment.Sameera Jayaseckara
I can't get a repro fro this in OWA. Just to be specific, you are clicking on another read mail in the mail list, and the item is changing in the reading pane, but no item change event is fired to your add-in? But in Outlook 2016 Desktop Client it works fine? (Note that if you compose a "new mail" it will not fire the event, as read/compose scenarios are handled separately in the manifest). Can you repro this with a very simple add-in that just registers for the add-in and doesn't do anything else? i.e just calls:Outlook Add-ins Team - MSFT
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, function (result) { console.log("received item change"); });Outlook Add-ins Team - MSFT

2 Answers

3
votes

I was experiencing the same issue. Thought to re-register the event handler and it worked.

Here is the code I am using.

Office.onReady(function() {
    //console.log('In Office.onReady');

    if(!Office.context.mailbox) {
        console.log('Run inside Outlook to be able to use it.');
        return;
    }
    console.log('Running in Office Add-in');

    // Set up ItemChanged event
    Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, selectedMailItemChanged);
    console.log('Item Change event registered.');

    doSomething(Office.context.mailbox.item);
    //console.log('Page initialized');
});

function selectedMailItemChanged(eventArgs) {
    console.log('Another email message selected');

    if(Office.context.mailbox.item != null) {
        doSomething(Office.context.mailbox.item);
    }
    else {
        console.log('No email is selected.');
        Office.context.mailbox.removeHandlerAsync(Office.EventType.ItemChanged, {handler: selectedMailItemChanged}, function(result) {
            console.log('Item Change event unregistered.');
            Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, selectedMailItemChanged);
            console.log('Item Change event re-registered.');
        });
    }
}

function doSomething(item) {
    // do something.
}

However, in another case where you can navigate to another web-page from within your add-in, while the add-in was still open, see this answer.

0
votes

It turns out that one cause of this behaviour (the cause?) is making a selection from a select control. It has been fixed in Office 16.0.13001.