makeEwsRequestAsync在Outlook桌面客户端

时间:2015-09-29 18:31:01

标签: outlook exchangewebservices office-addins office365-apps outlook-web-app

我正在使用makeEwsRequestAsync请求在outlook add中进行邮箱搜索。

var mailbox = Office.context.mailbox;
mailbox.makeEwsRequestAsync(request, callback);

它在Outlook Web客户端中运行良好但我在Outlook桌面客户端中总是得到空的结果。

回拨功能:

function callback(asyncResult) {

        var result = asyncResult.value;
        var context = asyncResult.context;

        if (asyncResult.status == "succeeded") {

            var xmlDoc = $.parseXML(result.toString());
}
}

在xml解析之后,$(xmlDoc).text()给出了xml文本。

但$(xmlDoc).find('node')在Outlook桌面客户端(Outlook 2013)中不起作用。我尝试以大写字母给出节点名称,较低(例如:s:Envelope,s:envelope,S:ENVELOPE),但find()不起作用

如何在Outlook桌面客户端中获取结果。我正在使用outlook 2013。

1 个答案:

答案 0 :(得分:1)

您需要根据客户端的不同来解析XML,并在https://msdn.microsoft.com/en-us/library/office/fp160952.aspx上进行讨论。如果您转储result.toString()的内容,您将能够告诉实际返回到Outlook中运行的Javascript处理器的内容,然后您应该能够确定如何正确处理它。

微软已经在GitHub上发布了很多例子,例如https://github.com/OfficeDev/Outlook-Add-in-JavaScript-MakeEWSRequest

我个人使用以下内容适用于大多数浏览器和桌面Outlook版本,但我通常首先输出结果以查看返回的内容,然后很容易找出下一步应该做什么以及哪些js对象是最好用



function callbackFindItems(asyncResult) {
    //$('#ChkTest').text(asyncResult.value);
    var result = asyncResult.value;
    var context = asyncResult.context;
    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    if (is_chrome) {
        var parser = new DOMParser();
        var doc = parser.parseFromString(asyncResult.value, "text/xml");
        var values = doc.childNodes[0].getElementsByTagName("ItemId");
        var itemId = values[0].attributes['Id'].value;
        var changeKey = values[0].attributes['ChangeKey'].value;
        var request = UpdateVerb(itemId, changeKey, hexToBase64(_VerOptions));
        var envelope = getSoapEnvelope(request);
       // $('#ChkTest').text(request);
        Office.context.mailbox.makeEwsRequestAsync(envelope, updateCallBack);
    }
    else {
        var parser = new DOMParser();
        var doc = parser.parseFromString(asyncResult.value, "text/xml");
        var values = doc.childNodes[0].getElementsByTagName("t:ItemId");
        var itemId = values[0].attributes['Id'].value;
        var changeKey = values[0].attributes['ChangeKey'].value;
        var request = UpdateVerb(itemId, changeKey, hexToBase64(_VerOptions));
        var envelope = getSoapEnvelope(request);
        //$('#ChkTest').text(request);
        Office.context.mailbox.makeEwsRequestAsync(envelope, updateCallBack);
    }
}




相关问题