注册Office.EventType.ItemChanged时,Outlook WebAddin引发内部服务器错误 [英] Outlook WebAddin throwing internal server error when registering Office.EventType.ItemChanged

查看:94
本文介绍了注册Office.EventType.ItemChanged时,Outlook WebAddin引发内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Outlook WebAddin中,我正在尝试使用以下代码注册邮件ItemChange事件.

In my outlook WebAddin, i am trying to register for mail ItemChange event using below code.

    Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, mailItemSelectionChanged, [], function (result) {
            if(result && result.status != 'succeeded'){
                console.error('result => ' + result);
             }
});

每当用户在固定模式下更改邮件时,我都会第一次收到邮件更改事件.然后,如果对话发生变化,我将使用 location.reload()重新加载插件,以清除缓存并重新加载插件.

Whenever user changes mail in pinned mode, i receive mail change event for first time. then if there is change in conversation, i am reloading the plugin with location.reload() to clear the cache and load addin fresh.

重新加载插件后,它无法注册mailItemChange事件并抛出以下错误:

After reload of plugin, it fails to register mailItemChange event and throwing below error :

{代码":5001,消息":发生内部错误.",名称": 内部错误"}

{"code": 5001, "message": "An internal error has occurred.", "name": "Internal Error"}

在浏览器和某些Windows计算机(在许多其他情况下都可以使用)中失败.

It is failing in Browser and some windows machines(working in many other cases).

outlookDiagnostics :

{主机":"Outlook",平台":"OfficeOnline",版本": "16.0.9215.1000"}

{"host": "Outlook", "platform": "OfficeOnline", "version": "16.0.9215.1000"}

推荐答案

我可以找出有关Office.EventType.ItemChanged事件注册的以下行为:

I could figure out the following behaviors with respect to Office.EventType.ItemChanged event registration:

  1. 您不能注册多个事件处理程序.大多数人在第二次尝试注册事件处理程序时都遇到了错误,从而使第一个事件处理程序没有被注销.
  2. 事件处理程序的注册有效期已超出外接程序网页的有效期.这意味着,当您的加载项卸载当前网页并重新加载相同或不同的网页(即,它导航到另一个网页)时,事件处理程序的注册仍将保留.
  3. 在注销事件处理程序时,您不仅必须提供处理程序函数的名称,而且还必须确保该函数与用于注册事件的函数完全相同.换句话说,如果您尝试在重新加载网页之后注销事件处理程序,则处理程序功能的对象不相同,因此事件处理程序也不会被注销.
  4. Outlook关闭加载项窗格时,事件处理程序注册会丢失.

因此,根据您的情况,您需要在调用location.reload()之前注销事件,如下所示.

So in your case, you need to unregister the event before calling the location.reload() as shown below.

Office.context.mailbox.removeHandlerAsync(Office.EventType.ItemChanged, {handler: mailItemSelectionChanged}, function(result) {
    if (result.status === Office.AsyncResultStatus.Failed) {
        console.log('Item Change event could not be unregistered.');
        console.log(result.error);
    }
    else {
        console.log('Item Change event unregistered successfully.');
    }
});
setTimeout(function() {location.reload();}, 100);

那些想要从其外接程序导航到相同或另一个网页的人,他们可以将click事件处理程序附加到定位标记(或按钮),以确保在当前事件之前已注销ItemChanged事件处理程序.页面已卸载.我使用以下代码完成了此操作:

Those who want to navigate to the same or another web-page from their add-in, they can attach click event handlers to the anchor tags (or buttons) in order to ensure that ItemChanged event handlers have been unregistered before the current page is unloaded. I have done this using the following code:

$(document).ready(function() {
    $('.NavBarContainer a').toArray().forEach(function(anchor1, index) {
        $(anchor1).click(function(event) {
            if(itemChangeEventRegistered) {
                unregisterItemChangeHandler();
                setTimeout(function() {window.location = anchor1.href;}, 100);
                return false;
            }
            return true;
        });
    });
});

这篇关于注册Office.EventType.ItemChanged时,Outlook WebAddin引发内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆