Outlook Add-In API does not fire the ItemChange event consistently on Firefox/Chrome

主宰稳场 提交于 2019-12-08 07:12:54

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/50351654/outlook-add-in-api-does-not-fire-the-itemchange-event-consistently-on-firefox-ch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!