I'm doing a mail box search in outlook add on using makeEwsRequestAsync request.
var mailbox = Office.context.mailbox;
mailbox.makeEwsRequestAsync(request, callback);
It is working good in outlook web client but I always get empty result in outlook desktop client.
call back function:
function callback(asyncResult) {
var result = asyncResult.value;
var context = asyncResult.context;
if (asyncResult.status == "succeeded") {
var xmlDoc = $.parseXML(result.toString());
}
}
After xml parsing, $(xmlDoc).text() gives the xml text.
But $(xmlDoc).find('node') is not working in outlook desktop client (Outlook 2013). I tried giving the node name in capitals, lower (eg. s:Envelope, s:envelope, S:ENVELOPE) but find() is not working
What should I do to get the result in outlook desktop client. I'm using outlook 2013.
You need to parse the XML differently depending on the client there's a discussion in https://msdn.microsoft.com/en-us/library/office/fp160952.aspx on it. If you dump the contents of result.toString() you will be able to tell what is actually being returned to the Javascript processor running in Outlook and you should then be able to work out how process it correctly.
There are number of examples Microsoft have posted on GitHub eg https://github.com/OfficeDev/Outlook-Add-in-JavaScript-MakeEWSRequest
Personally I use the following which works across most browsers and desktop outlook version but I generally work by outputting the results first to see what is being returned and then its easy to work out what you should be doing next and which js objects are best to use
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);
}
}